0% found this document useful (0 votes)
25 views

Worksheet 1 (Revision Tour 1 & 2)

The document contains a series of programming questions and tasks related to Python, including expressions, data types, loops, and string manipulations. It also includes code snippets that require debugging and output prediction. The questions test knowledge of Python syntax, logic, and functionality.

Uploaded by

Bhuvan Harshaj
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 views

Worksheet 1 (Revision Tour 1 & 2)

The document contains a series of programming questions and tasks related to Python, including expressions, data types, loops, and string manipulations. It also includes code snippets that require debugging and output prediction. The questions test knowledge of Python syntax, logic, and functionality.

Uploaded by

Bhuvan Harshaj
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/ 4

1) Write the output for the expression: not ((True and False) or True)

2) str1= “Class” + “Work”


Assertion (A) : Value of str1 will be “ClassWork”
Reason(R): Operator ‘+’ adds the operands, if both are numbers &
concatenates the string if both operands are strings.
Both A and R are true and R is the correct explanation for A.
Both A and R are true and R is not the correct explanation for A.
A is true but R is false. A is false but R is true
3) State True or False: “Python has a set of keywords that can also be used
to declare variables”
4) The explicit conversion of an operand to a specific type is called _____
5) What will be the data type of d, if d = 15 ?
6) Write the output for the expression not 5 or 4 and 10 and 'bye'.
7) What will the following expression be evaluated to in Python?
print (25//4 +3**1**2* 2)
8) Which of the following is an invalid identifier in Python?
(a) Max_marks (b) Max–marks (c) Maxmarks (d) _Max_Marks
9) Predict the output for the following snippet code:
count =0
while (True):
if (count%3 ==0):
print (count, end=’’)
if (count>15):
break
count+=1
10) What will the following expression be evaluated to in Python?
print (16-(3+2) *5+2**3*4)
11) Add a pair of parentheses to each expression so that it evaluates to True.
a) 2+3==4+5 ==7 b) 0 ==1 ==2
12) What will be the data type of the expression 12/5==0?
13) Mohit has written a code to input a positive integer and display its
factorial. His code is having errors. Rewrite the correct code and underline
the corrections made. (factorial of a number n is the product 1x2x3. . .n)
n=int(input("Enter a positive integer: ")
f=0
for i in range(n):
f*=i
print(f)
14) Write the output for the expression: 1 7%5==2 and 4%2>0 or 15//2==7.5
15) What will be the result of the following statements? a) bool(int(“0”)) b)
type(“hello”)
16) State True or False: Python does not allow same variable to hold different
data literals / data types.
17) What will the following expression be evaluated to in Python?
print( ( - 33 // 13) * (35 % -2)* 15/3)
18) State True or False: "In Python, data type of a variable depends on its
value"
19) Why is following code giving errors? Explain and correct the code.
Name=”Rehman”
print(“Greetings!!!”)
print(“Hello”, Name)
print(“How do you do”)
20) Write the Jump statements in Python.

21) 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
22) Find and write the output of the following python code:
Data = ["P",20,"R",10,"S",30]
Times = 0
Alpha = ""
Add = 0
for C in range(1,6,2):
Times= Times + C
Alpha= Alpha + Data[C-1]+"$"
Add = Add + Data[C]
print Times, Add, Alpha
23) Find and write the output of the following python code:
Text1="AISSCE 2018"
Text2=""
I=0
while l<len(Text1):
if Text1[I]>="0" and Text1[I]<="9":
Val = int(Text1[I])
Val = Val + 1
Text2=Text2 + str(Val)
elif Text1[I]>="A" and Text1[I] <="Z":
Text2=Text2 + (Text1[I+1])
else:
Text2=Text2 + "*"
I=I+1
print Text2
24) Find and write the output of the following python code:
TXT = ["20","50","30","40"]
CNT = 3
TOTAL = 0
for C in [7,5,4,6]:
T = TXT[CNT]
TOTAL = float (T) + C
print TOTAL
CNT-=1
25) Find and write the output of the following python code:
Moves=[11, 22, 33, 44]
Queen=Moves Moves[2]+=22
L=len(Moves)
for i in range (L):
print “Now@”, Queen[L-i-1], “#”, Moves [i]
26) Find the output of the following
L1 = [100,900,300,400,500]
START = 1
SUM = 0
for C in range(START,4):
SUM = SUM + L1[C]
print(C, ":", SUM)
SUM = SUM + L1[0]*10
print(SUM)
27) fruit_list1 = ['Apple', 'Berry', 'Cherry', 'Papaya']
fruit_list2 = fruit_list1
fruit_list3 = fruit_list1[:]
fruit_list2[0] = 'Guava'
fruit_list3[1] = 'Kiwi'
sum = 0
for ls in (fruit_list1, fruit_list2, fruit_list3):
if ls[0] == 'Guava':
sum += 1
if ls[1] == 'Kiwi':
sum += 20
print (sum)
28) s=”school2@com”
k=len(s)
m=" "
for i in range(0,k):
if(s[i].isupper()):
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
else:
m=m+'bb'
print(m)
29) Write a python program to count the number of vowels present in the
entered string without using inbuilt function.
30) Write a python program to create list1 and list2 and merge two lists by
creating list3. Print list1, list2, list3.

You might also like