Question: This lab is designed to let you recall knowledge learned in your ITW 2 4 3 0 as well as get familiar with the lab

This lab is designed to let you recall knowledge learned in your ITW 2430 as well as get familiar with the lab/project report format and online submission system of this course.
Try to write your answers first without run the code and then verify your answers by running the code. In case you made a mistake, make sure you know the reason.
This lab need to submit on time using the online submission system, but it will not be graded, check the answers yourself by running the code.
Prob. 1. What is the type of each of the following expressions (within the type function)?
Program Text: Output:
print(type(5))_____________________
print(type("abc"))_____________________
print(type(True))_____________________
print(type(5.5))_____________________
print(type(12/27))_____________________
print(type(12//27))_____________________
print(type(2.0/1))_____________________
print(type(2.0//1))_____________________
print(type(12**3))_____________________
print(type(12.0**3))_____________________
print(type(5==5))_____________________
a = str((-4+ abs(-5)//2**3)+321-((64//16)%4)**2)
print(type(a))
print(a)
Output:
a= str((-4+ abs(-5)/2**3)+321-((64/16)%4)**2)
print(type(a))
print(a)
Output:
Prob. 2 Consider the following code
Program Text:
a =?
if a >10 and a %6=3:
print(a)
elif a >10 and a <20:
print(b)
else:
print(c)
Give a value for a that would produce the following outputs. If no value of a would produce that
output, write none.
Value of a: Output:
____________________ a b
____________________ a
____________________ b
____________________ c
____________________ Python is fun!
Prob. 3 What is the output of the following code? If the code does not terminate, write error.
Program Text:
a =5
while a <8:
print("X")
Output:
Program Text:
a =-1
while a <3:
print("X")
a = a +1
Output:
a =1
while a %7!=0:
if a %2==0:
print("O")
if a ==2:
print("X")
a = a +1
Output:
Prob. 4 Were going to show you variants of the same code. Write the output of each code snippet.
Program Text:
keep_going = True
a =0
b =0
while keep_going:
print("O")
a = a +5
b = b +7
if a + b >=24:
keep_going = False
Output:
We rearranged the code within the while loop here.
Program Text:
keep_going = True
a =0
b =0
while keep_going:
print("O")
if a + b >=24:
keep_going = False
a = a +5
b = b +7
Output:
The remaining two variants are duplicates of the first two with >= replaced by >.
Program Text:
keep_going = True
a =0
b =0
while keep_going:
print("O")
a = a +5
b = b +7
if a + b >24:
keep_going = False
Output:
Program Text:
keep_going = True
a =0
b =0
while keep_going:
print("O")
if a + b >24:
keep_going = False
a = a +5
b = b +7
Output:
Prob. 5 What is the output of the following code? If the code does not terminate, write error.
Program Text:
a =0
while a <3:
while True:
print("X")
break
print("O")
a = a +1
Output:
Program Text:
a =1
while a <3:
while a <3:
print("O")
a = a +1
Output:
Program Text:
a =1
while a <3:
if a %2==0:
b =1
while b <3:
print("X")
b = b +1
print("O")
a = a +1
Output:
Program Text:
a =1
while a <3:
b =1
while b <3:
if a ==2:
print("X")
print("O")
b = b +1
print("O")
a=a+1
Output:
Prob. 6 What is the output of the following code? If the code does not terminate, write error.
Program Text:
def f(a):
a = a +5
return a
b =0
f(b)
print(b)
b = f(b)
print

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!