0% found this document useful (0 votes)
54 views7 pages

Hots Fun

This document contains 11 code snippets with questions about output. The summaries are: 1) The code snippets test input/output, functions, parameters, global vs local variables, lists, strings and conditionals. The output requested is printed values and return values. 2) Common operations tested include mathematical operations, string/list manipulation, conditional logic, function definitions and calls, parameter passing, and global/local scope. 3) The goal is to run the code snippets and determine the printed or returned output based on the operations and flow of the programs.

Uploaded by

Himanshu.tewari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views7 pages

Hots Fun

This document contains 11 code snippets with questions about output. The summaries are: 1) The code snippets test input/output, functions, parameters, global vs local variables, lists, strings and conditionals. The output requested is printed values and return values. 2) Common operations tested include mathematical operations, string/list manipulation, conditional logic, function definitions and calls, parameter passing, and global/local scope. 3) The goal is to run the code snippets and determine the printed or returned output based on the operations and flow of the programs.

Uploaded by

Himanshu.tewari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Find out error

1) DEF execmain ( ) :
x = input (“Enter a number :”)
if (abs (x) = x ) :
print “You entered a positive number : “
else :
x=*-1
print “You entered made a positive number : “ x
execmain ( )
Ans:
def execmain():
x=input(“Enter a number: “)
if (abs(x)==x):
print("You entered a positive
number") else:
x *=-1
print("Number made positive:",x)
execmain()

2) def Tot(Number)
sum=0
for c in Range (1,Number+1):
sum+=c
RETURN sum
Print Tot[3]
Print Tot[6]

Ans:
def Tot(Number) :
sum=0
for c in Range (1,Number+1):
sum+=c
return sum
print (Tot[3])
print (Tot[6])

Find out output of following code


1) def sum(a,b,c):
return a+5, b+4, c+7
s1, s2, s3=sum(2, 3, 4)
print(s1, s2, s3)
Ans: 7 7 11

2) x=5
def funct2():
x=3
global x x=x+1
print x
Ans: 5
3) def changer(p,q=10):
p=p/q
q=p%q
print(p,’#’,q)
return p
a=200
b=20
a=changer(a,b)
print(a,’$’,b)
b=changer(b)
print(a,’$’,b)
a=changer(a)
print(a,’$’,b)
Ans: 10.0 # 10.0
10.0 $ 20
2.0 # 2.0
10.0 $ 2.0
1.0 # 1.0
1.0 $ 2.0
4) def myfunc( n):
n.append(4)
return n
L=[1,2,3]
M=myfunc(L)
print(L, M)
Ans: [1, 2, 3, 4] [1, 2, 3, 4]

5) Find and write the output of the following python code:


def state1():
global tigers
tigers =15
print(tigers)
tigers =95
print(tigers)
state1()
print(tigers)
Ans: 95
15
15

6) def SMS(X):
L=len(X)
for t in range (L):
if (X[t] in ['a','e','i','o','u']):
X[t]="&"
elif (X[t] in ['A','E','I','O','U']):
X[t]="$"
print(X)
SMS(list("HOWAreU2019"))

Ans: ['H', '$', 'W', '$', 'r', '&', '$', '2', '0', '1', '9']

7) def CALL1(M):
t1 = M%10
t2 = M%100
t3 = t1+t2
t4 = CALL2 (t3)
return t4

def CALL2(N):
a1=N/2
a2=a1 + N//3
return a2
answer=0
answer=CALL1(1234)
print(answer)
answer=CALL2(5678)
print(answer)

Ans: 31.0
4731.0

8) drink="Available"
food=None
def menu(x):
if x==drink:
print(drink)
else:
print(food)
menu(drink)
menu(food)
Ans: Available
None
9) x=5
def func():
x=1
print(x)
func()
print(x)
Ans: 1
5

10) def Alter(P=15,Q=10):


P=P*Q
Q=P/Q
Print(P,"#",Q)
return Q
A=100
B=200
A=Alter(A,
B)
Print(A,"$",
B)
B=Alter(B)
Print(A,"$",
B)
A=Alter(A)
Print(A,"$",B)
Ans:
20000 # 100.0
100.0 $ 200
2000 # 200.0
100.0 $ 200.0
1000.0 # 100.0
100.0 $ 200.0

11) def fun(s):


x=len(s)
m=’ ‘
for i in range(0,x):
if s[i].islower():
m+=s[i].isupper()
elif s[i].isalpha():
m+=s[i].islower()
else:
m+=‘bb’
print(m)
Fun(‘exam2@com’ )
Ans: EXAMbbbbCOM

You might also like