Q1) What is the purpose of a for loop in Python?
a) To define a function
b) To repeat statements a number of times
Q2) How is the range function typically used in a for loop?
a) range(start, end, step)
b) range(start, end)
Q3) What will the following code output?
for i in range(3):
print(i, end =' ')
Q 4) What is the output of the following code?
total = 0
for num in range(1, 6):
total += num
print(total)
Q5) What will the following code output?
for i in range(3):
for j in range(2):
print(i, j)
Q6) What will the following code output?
for char in 'hello':
if char == 'l':
break
print(char, end=' ')
Q7) What is the output of the following code snippet?
for i in range(5):
if i == 3:
continue
print(i)
Write the flow of following programs.
Program1:
1) count = 0
2) while count < 3:
3) print("Hello")
4) count += 1
Program2:
1) def func1():
2) return “hello”
3) def func2():
4) return “bye”
5) def func3():
6) return “hi”
7) num=int(input(“Please give the no”))
8) if num<0:
9) print(func1())
10) elif num >0:
11) print(func2())
12) else:
13) print(func3())
Program3:
1) num1= int(input(“Please give the no”))
2) num2= int(input(“Please give the no”))
3) for i in range(1,11,1):
4) if i%3==0:
5) print(num1//10)
6) else:
7) print( num2//10)