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)
Answer : 4. print all integers from 2 to n+1
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)
Answer : 2. 10
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))
Answer : 3. 9
36
72
72
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
Answer : 4. i%2==0
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
Answer : 2. i=i+2
No comments:
Post a Comment