Python : Looping
Statement Test 4
Q1. What is the use of range function in python?
Q2. Name three jump statements in python and explain any one.
Q3. Write the output of the following program.
Code |
Output |
x = "123" for i in x: print(i) |
|
i=8 while True: if i%3==0: break print("A") |
|
i=9 while True: if i%3==0: break print("A") |
|
i=0 while i<3: print(i) i=i+1 else: print(0) |
|
i=0 while i<3: print(i) i=i+1 print(0) |
|
i=0 while i<3: print(i) i=i+1 print(0) |
|
i=2 for x in range(i): i+=1 print(i) print(i) |
|
i=2 for x in range(i): x+=1 print(x) print(x) |
|
i=2 for x in range(i): x+=1 print(x) print(x) |
|
i=100 while i<57: print(i) i+=5 |
|
i=100 while i>57: print(i+1) i+=5 |
|
Q4.
Write the output and convert it into for loop.
i=100
while i>57:
print(i)
i-=5
Solution
of Q3.
Code |
Output |
x = "123" for i in x: print(i) |
1 2 3 |
i=8 while True: if i%3==0: break print("A") |
Infinite
loop |
i=9 while True: if i%3==0: break print("A") |
No
Output |
i=0 while i<3: print(i) i=i+1 else: print(0) |
0 1 2 0 |
i=0 while i<3: print(i) i=i+1 print(0) |
0 1 2 0 |
i=0 while i<3: print(i) i=i+1 print(0) |
0 0 1 0 2 0 |
i=2 for x in range(i): i+=1 print(i) print(i) |
3 3 4 4 |
i=2 for x in range(i): x+=1 print(x) print(x) |
1 2 2 |
i=2 for x in range(i): x+=1 print(x) print(x) |
1 1 2 2 |
i=100 while i<57: print(i) i+=5 |
No
Output |
i=100 while i>57: print(i+1) i+=5 |
Infinite
loop |
No comments:
Post a Comment