Function

[Set – 1]

1. Write a function find_max that accepts three numbers as arguments and returns the largest number among three. Write another function main, in main() function accept three numbers from user and call find_max. Solution

2. Write a function, is_vowel that returns the value true if a given character is a vowel, and otherwise returns false. Write another function main, in main() function accept a string from user and count number of vowels in that string. Solution

3. Write a function named is_prime, which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. Also, write the main function that displays prime numbers between 1 to 500. Solution

4. Write a function in python to find the sum of the cube of elements in a list. The list is received as an argument to the function, in turn, the function must return the sum. Write the main function which invokes the above function. Solution

5. Write the definition of a function zero_ending(scores) to add all those values in the list of scores, which are ending with zero and display the sum.

For example: If the scores contain [200, 456, 300, 100, 234, 678] The sum should be displayed as 600. Solution

6. Write a definition of a method count_now(places) to find and display those place names, in which there are more than 5 characters.

For example :
If the list places contains
["DELHI","LONDON","PARIS","NEW YORK","DUBAI"]
The following should get displayed :
LONDON
NEW YORK Solution

7. Write a method in python to display the elements of list thrice if it is a number and display the element terminated with ‘#’ if it is not a number.

For example, if the content of list is as follows :
ThisList=[‘41’,‘DROND’,‘GIRIRAJ’, ‘13’,‘ZARA’]
The output should be
414141
DROND#
GIRIRAJ#
131313
ZARA# Solution

8. For a given list of values in descending order, write a method in python to search for a value with the help of Binary Search method. The method should return position of the value and should return -1 if the value not present in the list. Solution

9. Write a function half_and_half that takes in a list and change the list such that the elements of the second half are now in the first half.

For example, if the size of list is even and content of list is as follows :
my_liist = [10,20,30,40,50,60]
The output should be
[40,50,60,10,20,30]
if the size of list is odd and content of list is as follows :
my_liist = [10,20,30,40,50,60,70]
The output should be
[50,60,70,40,10,20,30] Solution

10. Write a function that accepts a dictionary as an argument. If the dictionary contains duplicate values, it should return an empty dictionary. Otherwise, it should return a new dictionary where the values become the keys and the keys become the values.

For example, if the dictionary contains the following key-value pairs:
{'a': 10, 'b': 20, 'c': 20}
the function should return an empty dictionary {} because there are duplicate values.

On the other hand, if the dictionary contains the following key-value pairs:
{'a': 10, 'b': 20, 'c': 30}
the function should return a new dictionary {10: 'a', 20: 'b', 30: 'c'} where the values from the original dictionary become the keys, and the keys from the original dictionary become the values. Solution