DEAF 310 Homework 5.1 to 5.4 Solution
"Clunker Motors Inc. is recalling all vehicles in its Extravagant line
from model years 1999-2002. Given variables modelYear and
modelName write a statement that assigns True to recalled if the
values of modelYear and modelName match the recall details and
assigns false otherwise." ---100%Correct Answers--- "write a
statement that assigns True to recalled"
recalled =
"values of modelYear and modelName match the recall details"
this means that 1999<= modelYear<= 2002 and modelName ==
"Extravagant"
code:
recalled = 1999<= modelYear<=2002 and modelName ==
"Extravagant"
"Clunker Motors Inc. is recalling all vehicles in its Extravagant line
from model years 1999-2002. Given a variable modelYear and a
String modelName write a statement that prints the message
"RECALL" to standard output if the values of modelYear and
modelName match the recall details." ---100%Correct Answers--
- if (1999<=modelYear<=2002 and
modelName=="Extravagant"):
print("RECALL")
"Write a conditional that assigns True to fever if temperature is
greater than 98.6." ---100%Correct Answers--- conditional: if,
then statement
so need to be using if : format-
code:
if temperature > 98.6: fever = True
, conditional format ---100%Correct Answers--- if *****:
"Write a conditional that multiplies the value associated with pay
by one-and-a-half if worked_overtime is associated with True." ---
100%Correct Answers--- if worked_overtime == True: pay=
pay*1.5
or can do
if worked_overtime == True: pay*=1.5
"Given x and y, each associated with an int, write a fragment of
code that associates the larger of these with another variable
named max." ---100%Correct Answers--- if x > y:
max=x
else:
max=y
"Assume that the variables gpa, deansList and studentName,
have been initialized. Write a statement that adds 1 to deansList
and prints studentName to standard out if gpa exceeds 3.5." ---
100%Correct Answers--- if gpa>3.5:
deansList+=1
print(studentName)
"Assume that isIsosceles is a boolean variable , and that the
variables isoCount,triangleCount, and polygonCount have all
been initialized. Write a statement that adds 1 to each of these
count variables (isoCount,triangleCount, and polygonCount)if
isIsosceles is true." ---100%Correct Answers--- if isIsosceles
== True:
isoCount +=1
triangleCount += 1
polygonCount +=1
"Clunker Motors Inc. is recalling all vehicles from model years
1995-1998 and 2004-2006. Given a variable modelYear write a
"Clunker Motors Inc. is recalling all vehicles in its Extravagant line
from model years 1999-2002. Given variables modelYear and
modelName write a statement that assigns True to recalled if the
values of modelYear and modelName match the recall details and
assigns false otherwise." ---100%Correct Answers--- "write a
statement that assigns True to recalled"
recalled =
"values of modelYear and modelName match the recall details"
this means that 1999<= modelYear<= 2002 and modelName ==
"Extravagant"
code:
recalled = 1999<= modelYear<=2002 and modelName ==
"Extravagant"
"Clunker Motors Inc. is recalling all vehicles in its Extravagant line
from model years 1999-2002. Given a variable modelYear and a
String modelName write a statement that prints the message
"RECALL" to standard output if the values of modelYear and
modelName match the recall details." ---100%Correct Answers--
- if (1999<=modelYear<=2002 and
modelName=="Extravagant"):
print("RECALL")
"Write a conditional that assigns True to fever if temperature is
greater than 98.6." ---100%Correct Answers--- conditional: if,
then statement
so need to be using if : format-
code:
if temperature > 98.6: fever = True
, conditional format ---100%Correct Answers--- if *****:
"Write a conditional that multiplies the value associated with pay
by one-and-a-half if worked_overtime is associated with True." ---
100%Correct Answers--- if worked_overtime == True: pay=
pay*1.5
or can do
if worked_overtime == True: pay*=1.5
"Given x and y, each associated with an int, write a fragment of
code that associates the larger of these with another variable
named max." ---100%Correct Answers--- if x > y:
max=x
else:
max=y
"Assume that the variables gpa, deansList and studentName,
have been initialized. Write a statement that adds 1 to deansList
and prints studentName to standard out if gpa exceeds 3.5." ---
100%Correct Answers--- if gpa>3.5:
deansList+=1
print(studentName)
"Assume that isIsosceles is a boolean variable , and that the
variables isoCount,triangleCount, and polygonCount have all
been initialized. Write a statement that adds 1 to each of these
count variables (isoCount,triangleCount, and polygonCount)if
isIsosceles is true." ---100%Correct Answers--- if isIsosceles
== True:
isoCount +=1
triangleCount += 1
polygonCount +=1
"Clunker Motors Inc. is recalling all vehicles from model years
1995-1998 and 2004-2006. Given a variable modelYear write a