Function
Function
Functions
1 Rao has written a code to input a number and check whether it is prime or not. His code is having errors.
Rewrite the correct code and underline the corrections made.
`
2
3 What possible outputs(s) are expected to be displayed on screen at the time of execution of the program from
the following code. Select which option/s is/are correct
import random
print(random.randint(15,25) , end=' ')
print((100) + random.randint(15,25) , end = ' ' )
print((100) -random.randint(15,25) , end = ' ' )
print((100) *random.randint(15,25) )
(i) 15 122 84 2500
(ii) 21 120 76 1500 (
(iii) 105 107 105 1800
(iv) 110 105 105 190
Ans- (i ) (ii) are correct answers.
Options:
a. b.
RED* YELLOW*
WHITE* WHITE*
BLACK* BLACK*
RED* RED*
c. d.
WHITE* WHITE* YELLOW*
YELLOW* YELLOW* WHITE*WHITE*
BLACK* BLACK* BLACK* BLACK* BLACK*
RED* RED* RED* RED* RED* RED* RED*
Ans-
Option b
YELLOW*
WHITE*
BLACK*
RED*
6 Write a Python function named remove_Duplicates(word)that takes a string as an argument. The function should
return a new string with duplicate characters removed, preserving the order of the remaining characters. For
example, consider the following word: word = "programming" The function should return a new string with
duplicates removed: "progamin"
Ans :
string = "programming"
def remove_Duplicates(string):
ch = " "
for i in string:
if i not in ch:
ch = ch + i
print(ch)
remove_Duplicates(string)
7 Write a function REPLACE_EN(St) that takes string as an argument and returns a string in which all e and n are
replaced with ‘*’.
For example, if the string is St= Message your token number
Then output should be: St = M*ssag* your tok** *umb*r
Ans:
def REPLACE_EN(st):
newstr = ''
for character in st:
if character in 'enEN':
newstr += '*'
else:
newstr += character
return newstr
Ans:
def CHECK_PALLINDROM (String):
return String==String[::–1]
10 Write a program in Python, which accepts a list Arr of numbers , the function will replace the even number by
value 10 and multiply odd number by 5 . Sample Input Data of the list is: 30 arr=[10,20,23,45] output : [10, 10,
115, 225]