Practice Questions
I. Short Answers.
1)Evaluate the following expression:
i)A=15*16//4+10-8//4+10-2+50//10
print(A)
ii)a=25 b=37 c=44 d=77
print(not(a==b)or(c==d))
2)Write the output for the given code:
x= 15
for i in range(5):
x+=5
if x==30:
break
print("The X has value:", x)
print("The end")
3)Write the output for the given code:
for x in "program":
if x== "a":
break
print(x, end=””)
for l in ‘computer’:
if l== ‘u’:
continue
print (letter)
4. Consider the following python statement
n1,n2,n3=4,3,2
Consider the above variables (and values) for answering the questions given
below.
(a) Write the output of
x=2
x+=n2+n3
print(x)
(b) Write the output of
x=n1**(n2+n3)
print(x)
(c) Write the output of
x=n1//float(10)
print(x)
(d) Write the output of
x='5'+'5'
print(x)
II. Program Style questions
5. Write a Python program to print the below pattern
6. Rewrite the correct code by identifying the errors in the given code:
a) print("Hello, World')
x=5
y=3
result = x + y
print(result
b) name = "Abhay'
age == 30
print("My name is", name, "and I am", age, "years old
[Link] the precedence of operators from highest to lowest
8. Write a python program to calculate the grade..The grade will be
calculated according to the:
1. score >= 81 to 100: "A"
2. score >= 71 to 80: "B"
3. score >= 61 :70 "C"
4. score >= 41 :60 "D"
[Link]<=40: “E”
9. Explain the following with one example of each
(a) Keyword
(b) Identifier
(c) Token
(e) Operator