Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 as well as get familiar with the labproject 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. What is the type of each of the following expressions within the type function
Program Text: Output:
printtype
printtypeabc
printtypeTrue
printtype
printtype
printtype
printtype
printtype
printtype
printtype
printtype
a str abs
printtypea
printa
Output:
a str abs
printtypea
printa
Output:
Prob. Consider the following code
Program Text:
a
if a and a :
printa
elif a and a :
printb
else:
printc
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. What is the output of the following code? If the code does not terminate, write error.
Program Text:
a
while a :
printX
Output:
Program Text:
a
while a :
printX
a a
Output:
a
while a :
if a :
printO
if a :
printX
a a
Output:
Prob. Were going to show you variants of the same code. Write the output of each code snippet.
Program Text:
keepgoing True
a
b
while keepgoing:
printO
a a
b b
if a b :
keepgoing False
Output:
We rearranged the code within the while loop here.
Program Text:
keepgoing True
a
b
while keepgoing:
printO
if a b :
keepgoing False
a a
b b
Output:
The remaining two variants are duplicates of the first two with replaced by
Program Text:
keepgoing True
a
b
while keepgoing:
printO
a a
b b
if a b :
keepgoing False
Output:
Program Text:
keepgoing True
a
b
while keepgoing:
printO
if a b :
keepgoing False
a a
b b
Output:
Prob. What is the output of the following code? If the code does not terminate, write error.
Program Text:
a
while a :
while True:
printX
break
printO
a a
Output:
Program Text:
a
while a :
while a :
printO
a a
Output:
Program Text:
a
while a :
if a :
b
while b :
printX
b b
printO
a a
Output:
Program Text:
a
while a :
b
while b :
if a :
printX
printO
b b
printO
aa
Output:
Prob. What is the output of the following code? If the code does not terminate, write error.
Program Text:
def fa:
a a
return a
b
fb
printb
b fb
print
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started