I Hate CBT's

View Original

5.4.6 Rolling Dice

Question: 5.1.6: 2 Through 20 Even

Answer: x = 2

while x <= 20:

print (x)

x = x + 2

Question: 5.1.7: Divisibility

Answer: number= 3

numerator = int(input(“Enter a numerator: “))

denominator = int(input(“Enter denominator: “))

Use a while loop here to repeatedly ask the user for

a denominator for as long as the denominator is 0

(or, put another way, until the denominator is not

equal to 0).

if int(numerator / denominator) * denominator == numerator:

print(“Divides evenly!”)

else:

print(“Doesn’t divide evenly.”)

while number >3:

print(“code complete”)

Question: 5.2.5: Counting 10 to 100 by tens

Answer: for i in range(1,11):

print(i* 10)

Question: 5.2.8: Average Test Score

Answer: total = 0

for i in range(3):

score = int(input(“Enter a score: “))

total = total + score

average = total / 3.0

print (“Average: “ + str(average))

Question: 5.2.9: How Many Names?

Answer: full_name = ““

numberofnames = int(input(“How many names do you have? “))

for i in range(numberofnames):

next_name = input(“Enter a name: “)

fullname = fullname + next_name + “ “

print (full_name)