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/ 5
2 – MARKS
1. Evaluate the following expression:
False and bool(15/5*10/2+1) 2. If given A=2,B=1,C=3, What will be the output of following expressions: (i) print((A>B) and (B>C) or(C>A)) (ii) print(A**B**C) 3. Write the output of the code given below: p=10 q=20 p*=q//3 p=q**2 q+=p print(p,q) 4. Evaluate the following expressions: (a) 5 // 10 * 9 % 3 ** 8 + 8 – 4 (b) 65 > 55 or not 8 < 5 and 0 != 55 5. Fill in the blanks to execute loop from 10 to 100 and 10 to 1 (i)for i in range(_______ ): print(i) (ii)for i in range( _______): print(i) 6. Evaluate the following: >>> print(15.0/4+(8*3.0)) 7. Sona has written the following code to check whether number is divisible by 3. She could not run the code successfully. Rewrite the code and underline each correction done in the code. x=10 for I range in (a) if i%3=0: print(I) else pass 8. Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code. Value=30 for VAL in range(0,Value) if val%4==0: print (VAL*4) Elseif val%5==0: print (VAL+3) else print(VAL+10) 9. Mona has written a code to input a positive integer and display all its even factors in descending order. Her code is having errors. Rewrite the correctcode and underline the corrections made. n=input("Enter a positive integer: ") for i in range(n): if i%2: if n%i==0: print(i,end=' ') 10. Find error in the following code(if any) and correct code by rewriting code and underline thecorrection;‐ x= int(“Enter value of x:”) for in range [0,10]: if x=y print( x + y) else: print( x‐y) 11. Mithilesh has written a code to input a number and evaluate its factorial and then finallyprint the result in the format : “The factorial of the <number> is <factorial value>” His codeis having errors. Rewrite the correct code and underline the corrections made. f=0 num = input("Enter a number:") n = num while num> 1: f = f * num num -= 1 else: print("The factorial of : ", n , "is" , f) 12. Rewrite the following code after removing the syntactical error(if any).Underline each correction: X=input("Enter a Number") If x % 2 =0: for i range (2*x): print i loop else: print "#" 13. What possible outputs are expected to be displayed on screen at the time of execution of the program from the following code? Also specify the maximum value that can be assigned to each of the variables L and U. import random Arr=[10,30,40,50,70,90,100] L=random.randrange(1,3) U=random.randrange(3,6) for i in range(L,U+1): print(Arr[i],"@",end="") (i) 40 @50 @ (ii) 10 @50 @70 @90 @ (iii) 40 @50 @70 @90 @ (iv) 40 @100 @ 14. Rewrite the following Python program after removing all the syntactical errors (if any), underlining each correction: 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” 15. (i)Find the output generated by the following code: a=5 b=10 a+=a+b b*=a+b print(a,b)
(ii)Answer the following questions from the following code:
num_list=["One","Two","Three","Four"] for c in num_list: print(c) (i) What will be the output of the above code? (ii) How many times the loop executed? 16. Predict the output of the following code: num=123 f=0 s=0 while(num > 3): rem = num % 100 if(rem % 2 != 0): f += rem else: s+=rem num /=100 print(f-s) 17. Evaluate the following expressions: a) 7*3+4**2//5-8 b) 7>5 and 8>20 or not 12>4 18. Predict the output of the following: for i in range(4): if i==4: break else: print(i) else: print("Welcome") 19. Anu wrote the code that, prints the sum of numbers between 1 and the number, for each number till 10.She could not get proper output. i=1 while (i <= 10): # For every number i from 1 to 10 sum = 0 # Set sum to 0 for x in range(1,i+1): sum += x # Add every number from 1 to i print(i, sum) # print the result a) What is the error you have identified in this code? b) Rewrite the code by underlining the correction/s. 20. Evaluate the following expressions: a) 6+7*4+2**3//5-8 b) 8<=20 and 11 21. Write the difference between break and continue. 22. Predict the output of the following: X=3 Y=5 Z = -2 X *= Y + Z Y -= X * 2 + Y Z += X + Y print(X, Y, Z) 23. Predict the output of the following code: X=3 Y=2 Z = -5 X -= Y + Z Y //= X - Z Z *= X + Y print(X, Y, Z) 24. Predict the output of the following: M, N, O = 3, 8, 12 N, O, M = O+2, M*3, N-5. print(N,O,M) 25. V, W, X = 20, 15, 10 W, V, X = X-2, V+3, W*2. print(V,X,W) 26. Predict the output of the following: a=None b=None x=4 for i in range(2,x//2): if x%i==0: if a is None: a=i else: b=i break print(a,b) 27. Predict the output of the following: for i in range(1, 15, 2): temp = i if i%3==0: temp = i+1 elif i%5==0: continue elif i==11: break print(temp, end='$') 28. Predict the output of the following: P,S=1,0 for X in range(-5,15,5): P*=X S+=X if S==0: break else: print(P, "#", S) 29. Predict the output of the following: for x in range(1, 4): for y in range(2, 5): if x * y > 6: break print(x*y, end="#") 30. N=5 C=1 while (C<8): if(C==3 or C==5): C+=1 continue print(C,'*',N,'=',C*N) C+=1 *********************************************************************