Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Lab 6 – Python

Q1) Read the following program

 

a, b = eval(input('Enter two numbers, separated by a comma: '))
if a > b:
    c = a + 4
    if b > 5:
        b = b - 2
elif a % 2 == 1:
    if b * 2 < 20:
        a = a + 3
    else:
         a = a - 1
    c = b - 2
else:
    c = -1
    if a == b:
        a *= 2
a = a + c
print(a, b, c)

 

Please trace this program for the following inputs ( 2 points for each correct answer)
5,5
100,50
200,100
6,7
8,10
Q2) What will be printed by the following lines of code? ( 2 points )

 

number = 10
if number > 15 or number < 12:
    print("foo", end=" ")
elif number * 3 == 30:
    print("boo", end=" ")
if number != 7:
    print("goo", end=" ")

 

Q3) What will be printed by the following lines of code?
(Note the changes in indentation for some of the lines.) (3 points)


number = 10
if number > 15 or number < 12:
    print("foo", end=" ")
elif number * 3 == 30:
    print("boo", end=" ")
    if number != 7:
        print("goo", end=" ")

 

Answer:

Output Q1

Enter two numbers, separated by a comma: 5,5

11 5 3

Enter two numbers, separated by a comma: 100,50

204 48 104

Enter two numbers, separated by a comma: 200,100

404 98 204

Enter two numbers, separated by a comma: 6,7

5 7 -1

Enter two numbers, separated by a comma: 8,10

7 10 -1

 

Output Q2

foo goo

 

Output Q3

foo

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!