Question 1
What is printed by the following program?
for i in range(2, 0, -1): print(i * "ab")abababab
ab(nothing is printed)ababab
abab
Week 5 of Programming in Python: Iterations & ranges (contd.). Extra important questions based on the recent, changing patterns of the exams, from basic to advanced. Practise them in learning mode: each question has a worked solution.
What is printed by the following program?
for i in range(2, 0, -1): print(i * "ab")abab
abab
ab
(nothing is printed)
ababab
abab
What will be the output of the code below?
for i in range(4): print("#" * (i + 1))##
###
####
#####
# 1
# 2
# 3
# 4
#
##
###
####
#
##
###
Run the program in your head. What is the output?
for i in range(5): for j in range(2): print(i + j, end=" ") print()0 1
1 2
2 3
3 4
4 5
0 0
0 1
0 2
0 3
0 4
0 1 1 2 2 3 3 4 4 5
0 1
1 2
2 3
3 4
4 5
5 6
Authorise with Google to see every question with its answer and explanation and practise it in learning mode.