Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
21 views

LabInternal 1 Py

ok

Uploaded by

varmavarma2260
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

LabInternal 1 Py

ok

Uploaded by

varmavarma2260
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Write a function called gcd that takes parameters a and b and returns their
greatest common divisor.
2. Write a function called is_palindrome that takes a string argument and
returns True if it is a palindrome and False otherwise. Remember that you
can use the built-in function len to check the length of a string.
3. Write a function called is_sorted that takes a list as a parameter and returns
True if the list is sorted in ascending order and False otherwise.
4. Write a function called has_duplicates that takes a list and returns True if
there is any element that appears more than once. It should not modify the
original list.
5. Write a function called remove_duplicates that takes a list and returns a new
list with only the unique elements from the original. Hint: they don’t have to
be in the same order.
6. Write a python code to read a dictionary values from the user. Construct a
function to invert its content. i.e., keys should be values and values should
be keys.
7. Given a space-seperated numbers, write a program to print a list containing
the given number that are divisible by 3
Sample Input : 3 10 9 11 18 20
Sample Output: [3,9,18]
8. Write a program to check if the given number N is prime or not using a
function.
9. Given a number N, write a program that reads N numbers as input and prints
the product of the given N numbers
Sample Input:
3
2
3
7
Sample Output:
42
10. Given an integer number N as input. Write a program to print the double
triangular pattern of N lines using an asterisk(*) character
Sample Input:
4
Sample Output:
*
**
***
****
*
**
***
****
11.Write a program that reads two numbers N and K and prints the sum of the
kth power of all the numbers from 1 to N.
Sample Input:
5
3
Sample Output:
225

12. Given a string, write a program to remove all the words with k length.
Sample Input:
Tea is good for you
3
Sample Output:
is good
13.Given a string write a program to move all the numbers in it to its end.
Sample Input:
1good23morning456
Sample Output:
goodmorning123456

14.Write a program to create a menu-driven calculator that performs basic


arithmetic operations (+, -, /, and %).
Sample Input:
3+5
Sample Output:
8
15.Write a Python program that takes a string as input and uses list
comprehension to create a list of vowels present in the string. Then, count
the occurrences of each vowel in the list.
16.Write a Python program that takes a list of words as input and uses list
comprehension to create a dictionary where keys are the words and values
are the lengths of the corresponding words.
17.Write a Python program that takes a dictionary where keys are student
names and values are their scores. Use dictionary comprehension to create a
new dictionary where keys are student names and values are their
corresponding letter grades based on the following grading scale: A (90-
100), B (80-89), C (70-79), D (60-69), F (0-59).
18.Write a Python program that defines a custom exception class and raises it
under certain conditions.
19.Write a Python program that takes user input and converts it into an integer.
Handle the ValueError exception if the input cannot be converted to an
integer.
20.Write a Python function that takes a list and an element as input and returns
the count of occurrences of that element in the list.
21.Write a program that reads the marks M in Maths and marks P in Physics
and checks if both M and P are greater than 35 or sum of M and P is greater
than or equal to 100. Print Qualified if both M and P are greater than 35 or
sum of M and P is greater than or equal to 100. Otherwise print not
qualified.

You might also like