LabInternal 1 Py
LabInternal 1 Py
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