- Find and write the output of the following Python code:
STR = ["90","10","30","40"] COUNT = 3 SUM = 0 for I in [1,2,5,4]: S = STR[COUNT] SUM = float (S)+I print (SUM) COUNT-=1
Solution - What is the possible outcome(s) executed from the following code? Also, specify the maximum and minimum values that can be assigned to variable NUM.
import random NAV = ["LEFT","FRONT","RIGHT","BACK"] NUM = random.randint(1,3) NAVG = "" for I in range(NUM,1,-1): NAVG = NAVG+NAV[I] print (NAVG) (i) BACKRIGHT (ii) BACKRIGHTFRONT (iii) BACK (iv) LEFTFRONTRIGHT
Solution -
Choose the possible output(s) of the following code and write the MAX and MIN values of N and M respectively.
import random N=random.randint(0,2) M=random.randint(0,3) DOCK = [[1,2,3],[2,3,4],[3,4,5]] for R in range(N): for C in range(M): print(DOCK[R][C],end=" ") print() i. 1 2 3 ii. 1 2 3 iii. 1 2 iv. 1 2 2 3 4 2 3 4 2 3 2 3 3 4 5 3 4
Solution - Which of the following can be used as a valid variable identifier(s) in Python write the reason for each and every option:
- total
- 7Salute
- Que$tion
- global
- Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code:
TEXT=""GREAT DAY"" for T in range[0,7]: print (TEXT(T)) print (T+TEXT)
Solution -
Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code.
Val = int(rawinput("Value:")) Adder = 0 for C in range(1,Val,3) Adder+=C if C%2=0: Print (C*10) Else: print (C*) print (Adder)
Solution
-
Out of the following, find those identifiers, which cannot be used for naming Variable or Functions in a Python program:
Price*Qty class For do 4thCol totally Row3 _Amount
Solution -
Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code.
for Name in [Amar,Shveta,Parag] IF Name[0]='S': print(Name)
Solution - Find and write the output of the following python code :
Numbers = [9,18,27,36] for Num in Numbers: for N in range(1, Num%8): print(N,"#",end="") print()
Solution - Find and write the output of the following python code :
Msg1="WeLcOME" Msg2="GUeSTs" Msg3="" for I in range(0,len(Msg2)+1): if Msg1[I]>="A" and Msg1[I]<="M": Msg3=Msg3+Msg1[I] elif Msg1[I]>="N" and Msg1[I]<="Z": Msg3=Msg3+Msg2[I] else: Msg3=Msg3+"*" print (Msg3)
Solution - What will be the output of the following code:
dc1 = {} dc1[1] = 1 dc1['1'] = 2 dc1[1.0] = 4 sum = 0 for k in dc1: sum += dc1[k] print(sum)
Solution - What possible output(s) are expected to be displayed on the screen at the time of execution of the program from the following code? Also, specify the minimum values that can be assigned to each of the variables BEGIN and LAST.
import random VALUES=[10,20,30,40,50,60,70,80] BEGIN=random.randint(1,3) LAST=random.randint(BEGIN,4) for I in range(BEGIN,LAST+1): print (VALUES[I],"-",) i) 30 - 40 - 50 - ii) 10 - 20 - 30 - 40 - iii) 30 - 40 - 50 - 60 - iv) 30 - 40 - 50 - 60 - 70 -
Solution - Write a python program using a random module to generate random numbers between 15 and 35.
- Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code.
250 = Number WHILE Number<=1000: if Number=>750: print (Number) Number=Number+100 else print (Number*2) Number=Number+50
- Predict the output of the following code snippet :
1 2 3
x="hello world" print(x[:2],x[:-2],x[-2:]) print(x[2:-3],x[-4:-2])
Solution - Find the output of the following :
1 2 3 4
word="green vegetables" print(word.find('g',2)) print(word.find('veg',2)) print(word.find('tab',4,15))
Solution - What will be the output of the following code snippet? Also, justify your answer.
1 2 3 4 5 6
rec={'Name':'Python', 'Age':20, 'Addr':'SK01', 'Country':'India'} id1=id(rec) del rec rec={'Name':'C++', 'Age':40, 'Addr':'SK02', 'Country':'USA'} id2=id(rec) print(id1==id2)
Solution
Solution
Solution
Its fav
ReplyDelete