Python : Looping Statement Test 4

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

Most Recently Published

File Handling Test 6

 File Handling Test 6 Q1 . Do we need to use the close() function when we use 'with' statement to open a file? Q2. Which mode you wi...

CS - IP Assignment/Worksheet