Ch. 7 Flashcards

decision structures

1
Q

a statement that controls the execution of other statements

A

control structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

the best structure for implementing a multi-way decision in python

A

if-elif-else

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

an expression that evaluates to either true or false

A

boolean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

when program is being run directly (not imported), the value of __name__ is

A

main

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

the literals for type bool are

A

true, false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

placing a decision inside of another decision

A

nesting

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

taking the square root of a negative value with math.sqrt produces a(n)

A

ValueError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

a multiple choice decision is most likely to

A

multi-way decision

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

write a program to input number of hours worked and the hourly rate and calculate the total wages for the week

A

def main():
print(“Weekly pay calculator \n”)
hours = float(input(“Enter hours worked: “))
rate = float(input(“hourly wage: “))
if hours <= 40:
pay = hours * wage
else:
pay = 40 * wage + (hours-40) * 1.5 * wage

print("Your week's pay is ${0:0.2f}.".format(pay))

if __name__ == ‘__main__’:
main()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

quizzes are graded on the scale 5-A, 4-B, 3-C, 2-D, 1-F, 0-F. Write a program that accepts exam score as an input and uses a decision structure to calculate the corresponding grade

A

def main():
print(“Quiz grade calculator \n”)
score = int(input(“Enter quiz score: “))
if score == 5:
grade = “A”
elif score == 4:
grade = “B”
elif score == 3
grade = “C”
elif score == 2
grade = “D”
else:
grade = “F”

print("The grade is ", grade".")

if __name__ == ‘__main__’:
main()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

write a program that calculates a person’s BMI and prints message stating whether or not BMI is in healthy range

A

def main():
print(“BMI calculator \n”)
weight = float(input(“Enter weight: “))
height = float(input(“Enter height: “))
bmi = weight * 720 / height
print = (“Your BMI is “, bmi”.”)
if bmi < 19:
print(“You are below the healthy range.”)
elif bmi <= 25:
print(“You are in the healthy range.”)
else:
print(“You are above the healthy range.”)

if __name__ == ‘__main__’:
main()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly