






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A comprehensive set of python programming exercises designed to reinforce fundamental concepts and data structures. It covers topics such as arithmetic operators, logical operators, data types, loops, functions, and string manipulation. The exercises are suitable for beginners and provide practical examples to enhance understanding and coding skills.
Typology: Assignments
1 / 10
This page cannot be seen from the preview
Don't miss anything!







(i) // (ii)? (iii) < (iv) and
(i) Like (ii) and (iii) or (iv) is
(i) 7/2 (ii) 7//
print((A>B) and (B>C) or (C>A))
(i) 15//2 (ii) 15%
(i) If (ii) roll_no
Marks1, $Roll, Avg Marks, IF, _sales2008, while, name
Average, RegNo. , break, Sales_Q
(i) 100 (ii) False
(i) 50.7 (ii) “India”
print(print(10))
function: (i) floor() (ii) bar() (iii) randint() (iv) sin() (v) linspace() (vi) connect() (vii) dump() (viii) insort()
correction done in the code. 30=To for K in range(0,To) IF k%4==0: print (K*4) Else: print (K+3)
correction done in the code: a= work=true b=hello c=a+b FOR i in range(10) if i%7=0: continue
IF Name[0]='S': print(Name)
correction done in the code: a=b= c=a+b While c=<20: print(c,END="*") c+=
msg = "Technology 2025" print(msg[3:]) print(msg[:4],msg[4:]) print(msg[::-1]) print(msg[0:4],msg[11:10])
def display(s): l = len(s) m="" for i in range(0,l): if s[i].isupper(): m=m+s[i].lower() elif s[i].isalpha(): m=m+s[i].upper() elif s[i].isdigit(): m=m+"$" else: m=m+"*" print(m) display("[email protected]")
def Change(P ,Q=30): P=P+Q Q=P-Q print( P,"#",Q) return (P) R= S= R=Change(R,S) print(R,"#",S) S=Change(S)
def Alter(M,N=50): M = M + N N = M - N print(M,"@",N) return M A= B= A = Alter(A,B) print(A,"#",B) B = Alter(B)
def Total(Number=10): Sum= for C in range(1,Number+1): if C%2==0: continue Sum+=C return Sum print(Total(4)) print(Total(7)) print(Total())
def Change(P=10, Q=25): global X if P%6==0: X+= else: X+= Sum=P+Q+X print(P,'#',Q,'$',Sum) Change() Change(18,50) Change(30,100)
def Func1(A,B): if A % B == 0: return 10 else: return A + Func1(A,B-1) val = Func1(20,15) print(val)
execution of the program from the following code? Also specify the maximum values that can be assigned to each of the variables FROM and TO. import random AR=[20,30,40,50,60,70]; FROM=random.randint(1,3) TO=random.randint(2,4) for K in range(FROM,TO+1): print (AR[K],end=”#“) (i) 10#40#70# (ii) 30#40#50# (iii) 50#60#70# (iv) 40#50#70#
execution of the program from the following code? Also specify the maximum values that can be assigned to each of the variables BEGIN and END. import random RUNS = [40,55,60,35,70,50] BEGIN = random.randint(0,2) END = random.randint(1,3) for i in range(BEGIN,END+1): print(RUNS[i],end='#') (i) 60#35# (ii) 60#35#70#50# (iii) 35#70#50# (iv) 40#55#60#
execution of the program from the following code? Also specify the maximum values that can be assigned to each of the variables BEGIN and END. import random PICKER=random.randint(0,3) COLORS=["BLUE","PINK","GREEN","RED"] for I in COLORS: for J in range(1,PICKER): print(I,end="") print() (i) BLUE PINK GREEN RED (ii) BLUE BLUEPINK BLUEPINKGREEN BLUEPINKGREENRED (iii) PINK PINKGREEN PINKGREENRED (iv) BLUEBLUE PINKPINK GREENGREEN REDRED
(i) range(20) (ii) range(0,21) (iii) range(21) (iv) range(0,20)
(i) Day={1:‟monday‟,2:‟tuesday‟,3:‟wednesday‟} (ii) Day=(1;‟monday‟,2;‟tuesday‟,3;‟wednesday‟) (iii) Day=[1:‟monday‟,2:‟tuesday‟,3:‟wednesday‟] (iv) Day={1‟monday‟,2‟tuesday‟,3‟wednesday‟]
Info = ({„roll‟:[1,2,3],‟name‟:[„amit‟,‟sumit‟,‟rohit‟]}) (i) List (ii) Dictionary (iii) String (iv) Tuple
i) d1={1:'January',2='February',3:'March'} ii) d2=(1:'January',2:'February',3:'March'} iii) d3={1:'January',2:'February',3:'March'} iv) d4={1:January,2:February,3:March}
Myd={„empno‟:1,‟name‟:‟Vikrant‟,‟salary‟:50000} write python statement to print the message: Vikrant@
(i) Dictionaries are mutable (ii) Dictionary items can be accessed by their index position (iii) No two keys of dictionary can be same (iv) Dictionary keys must be of String data type
Myd={„empno‟:1,‟name‟:‟Vikrant‟,‟salary‟:50000} Raj, Python programmer wants to print all the keys of dictionary and values stored in dictionary, Help Raj by filling the blanks given in print() statenebt to achieve the task: print(__________) print(__________)
L = [1, 23, „hi‟, 6]. (i) list (ii) dictionary (iii) array (iv) tuple
(i) L[80] (ii) L[4] (iii) L[L] (iv) L[3]
Rec=(1,‟Vikrant,50000) (i)List (ii) Tuple (iii) String (iv) Dictionary
string. (i)STR[::-1] (ii)STR[0,LEN(str)] (iii) STR[-1:-1:0] (iv) STR[-1:-len(STR)-1:-1]
for i in range(1,12): if i%2==0: continue print(i)
for i in range(1,12): if i%6==0: break print(i)
for w in x: if w=="a": print("*") else: print(w)
num= while num==1: print(num) num+= print(num*10)
a = 1 def f(): a = 10 print(a)
for k in range (10,20,5): print(k)
colors=["violet", "indigo", "blue", "green", "yellow", "orange", "red"] del colors[4] colors.remove("blue") colors.pop(3) print(colors)
till the 3rd iteration
def checkval: x = input("Enter a number") if x % 2 = 0: print x, "is even" else if x<0: print x, "should be positive" else; print x, "is odd"
def myfunc(a): a = a + 2 a = a * 2 return a print(myfunc(2))
def example(a): a = a + '2' a = a* return a example("hello")