0% found this document useful (0 votes)
25 views3 pages

Output Based

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

Output Based

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

#Find and write the output of the following python code:

def fun(s): def makenew(mystr):


k=len(s) newstr = " "
m=" " count = 0
for i in range(0,k): for x in mystr:
if(s[i].isupper()): if count%2 != 0:
m=m+s[i].lower() newstr = newstr + str(count)
elif s[i].isalnum(): else:
m=m+s[i].upper() if x.islower():
else: newstr = newstr + x.upper()
m=m+'bb' else:
print(m) newstr = newstr + x
fun('school2@com') count += 1
newstr = newstr + mystr[:1]
print("The new string is:", newstr)
makenew("sTUdeNT")
OUTPUT:- SCHOOL2bbCOM OUTPUT:- The new string is: ST11111s
s="welcome2cs" my_dict = {"name": "Aman", "age": 26}
n = len(s) my_dict['age'] = 27
m="" print(my_dict)
for i in range(0, n): my_dict['address'] = "Delhi"
if (s[i] >= 'a' and s[i] <= 'm'): print(my_dict)
m = m +s[i].upper() print(my_dict.items())
elif (s[i] >= 'n' and s[i] <= 'z'): print(my_dict.values())
m = m +s[i-1]
elif (s[i].isupper()): OUTPUT
m = m + s[i].lower() {'name': 'Aman', 'age': 27}
else: {'name': 'Aman', 'age': 27, 'address': 'Delhi'}
m = m +'&' dict_items([('name', 'Aman'), ('age', 27), ('address',
print(m) 'Delhi')])
dict_values(['Aman', 27, 'Delhi'])
OUTPUT:- sELCcME&Cc
#Ques:-Given is a Python string declaration: import random
myexam="@@CBSE Examination 2022@@" X= random.random() # value between 0 to 1
print(myexam[::-1]) Y= random.randint(0,4) # vlaues 0 to 4
print(myexam[::-2]) print(int(X),":",Y+int(X))
print(myexam[3:7:1])
print(myexam[0:5:]) write maximum and the minimum values X and Y
OUTPUT:- Ans- Max value of x will be 0.999
@@2202 noitanimaxE ESBC@@ Min. value of y will be 0
@20 otnmx SC@ Max value of x will be 4
BSE Min. value of y will be 0
@@CBS Possible outputs :-
Ans- 0:0,0:1,0:2,0:3,0:4
Moves=[11, 22, 33, 44] def Diff(N1,N2):
Queen=Moves if N1>N2:
Moves[2]+=22 return N1-N2
print("Values of Moves",Moves) else:
print("Values of Queen",Queen)
return N2-N1
L=len(Moves)
for i in range (L): NUM= [10,23,14,54,32]
print("Now@", Queen[L-i-1], "#", Moves [i]) for CNT in range (4,0,-1):
OUTPUT A=NUM[CNT]
Values of Moves [11, 22, 55, 44] B=NUM[CNT-1]
Values of Queen [11, 22, 55, 44] print(Diff(A,B),'#', end=' ')
Now@ 44 # 11
Now@ 55 # 22 OUTPUT
Now@ 22 # 55 22 # 40 # 9 # 13 #
Now@ 11 # 44
p=5
tuple1 = (11, 22, 33, 44, 55 ,66) def sum(q,r=2):
list1 =list(tuple1) global p
new_list = [] p=r+q**2
for i in list1: print(p, end= '#')
if i%2==0:
new_list.append(i) a=10
new_tuple = tuple(new_list) b=5
print(new_tuple) sum(a,b) # FUNCTION CALL
sum(r=5,q=1) # FUNCTION CALL
OUTPUT OUTPUT
(22, 44, 66) 105#6#

Question:-Rewrite the following code in Python after removing all syntax error(s). Underline each correction
done in the code.

INCORRECT CODE: ANSWER:-CORRECTED CODE:


Value=30 Value=30
for VAL in range(0,Value) for VAL in range(0,Value) : # Error 1
If val%4==0: if val%4==0: # Error 2
print (VAL*4) print (VAL*4)
Elseif val%5==0: elif val%5==0: # Error 3
print (VAL+3) print (VAL+3)
else else: # Error 4
print(VAL+10) print(VAL+10)

Y=integer(input(“Enter 1 or 10”)) Y=int(input(“Enter 1 or 10”)) # Error 1


if Y=10: if Y==10: # Error 2
for Y in range(1,11) for Y in range(1,11): # Error 3
print(Y) print(Y)
else: else:
for m in range(5,0,-1): for m in range(5,0,-1):
Print(thank you) print(“thank you”) # Error

def execmain(): def execmain():


x = input("Enter a number:") x = int(input("Enter a number:")) # Error 1
if (abs(x)= x): if (abs(x)== x): # Error 2
print("You entered a positive number") print("You entered a positive number")
else else: # Error 3
x=*-1 x*=-1 # Error 4
print("Number made positive : ",x) print("Number made positive : ",x)
execmain() execmain()

30 = To To = 30 # Error-1
for K in range(0,To) for K in range(0, To): # Error-2
IF k%4== 0: if k%4 == 0: # Error-3
print (K * 4) print (K * 4)
Else: else: # Error-4
print (K + 3) print (K + 3)

x= int(“Enter value of x:”) x= int(input(“Enter value of x:”)) # Error 1


for in range [0,10]: for in range (0,10): # Error 2
if x=y if x==y: # Error 3
print( x + y) print( x+y)
else: else:
Print( x‐y) print (x‐y) # Error 4

STRING=""WELCOME STRING= "WELCOME" # Error 1


NOTE"" NOTE=" " # Error 2
for S in range[0,7]: for S in range (0, 7) : # Error 3
print (STRING(S)) print (STRING [S]) # Error 4

You might also like