0% found this document useful (0 votes)
5 views

Function

c klllllljhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhvfvvvvkkk

Uploaded by

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

Function

c klllllljhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhvfvvvvkkk

Uploaded by

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

Worksheet – 1

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

st = input("Enter a String: ")


st1 = REPLACE_EN(st)
print("The original String is:",st)
print("The modified String is:",st1)
8 Write a function CHECK_PALLINDROM(String) that takes string as an argument and returns if a string is a
palindrome or not (A string is called palindrome if it reads the same backwards as forward). For example, if the
string is String = Naman Then output should be: The given string Naman is a palindrome.

Ans:
def CHECK_PALLINDROM (String):
return String==String[::–1]

String = input("Enter a string:")


result= CHECK_PALLINDROM (String)
if result==True:
print("The given String", str, "is a palindrome")
else:
print("The given String", str, "is not a palindrome")
9

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]

You might also like