Q:1. What does the following Python3 code do? (using python 3.X version):
n = int(input('Enter a number?'))
i = 1
while i <= n:
i = i+1
print (i)
i = 1
while i <= n:
i = i+1
print (i)
1.
2.
3.
4.
Q:2. What will the output of the following Python3 program (using python 3.X version)?
n = 13
sum = 0
while (n > 1):
n = n//2
sum = sum + n
print(sum)
sum = 0
while (n > 1):
n = n//2
sum = sum + n
print(sum)
1.
2.
3.
4.
Q:3. What will the output of the following Python3 program? If the program has error, select the option ERROR (using python 3.X version):
n,p = 9,1
while (n >= 1):
n,p = n//2,n*p
print(int(p))
while (n >= 1):
n,p = n//2,n*p
print(int(p))
1.
2.
3.
4.
Q:4. The following code should print all positive even numbers less than or equal to N. N is taken as input from the user. What should replace the X for the code to work correctly?(using python 3.X version):
N = int(input('Enter N:'))
i = 1
while ( i < N ) :
if ( X ):
print(i)
i = i + 1
i = 1
while ( i < N ) :
if ( X ):
print(i)
i = i + 1
1.
2.
3.
4.
4-If any no is divided by 2 completely then it is even no .So if(i%2==0) is true then it will be print even numbers till N.
Q:5. The following code should print all positive odd numbers less than or equal to N. N is taken as input from the user. What should replace the X for the code to work correctly? (using python 3.X version):
N = int(input('Enter N:'))
i = 1
while ( i < N ) :
print(i)
X
i = 1
while ( i < N ) :
print(i)
X
1.
2.
3.
4.
0 Comments