looping in python codehs

Ace your homework & exams now with Quizwiz!

5.3.7: Higher/ Lower

magic_number = 3 while True: guess = int(input("Guess my number: ")) if guess == magic_number: print("Correct!") break print("Too high!") # Print this sentence once number has been guessed print("Great job guessing my number!") # Your code he

5.2.8: Average Test Score

total = 0 for i in range(3): score = int(input("Enter a score: ")) total = total + score average = total / 3.0 print ("Average: " + str(average))

5.1.6: 2 Through 20 Even

x = 2 while x <= 20: print (x) x = x + 2

5.4.6: Rolling Dice

#set numbers i in range for i in range(1,7): #set numbers j in range for j in range(1,7): #print dice numbers print (str(i) + "," + str(j))

5.2.5: Counting 10 to 100 by tens

for i in range(1,11): print(i* 10)

5.4.7: Categories

for i in range(3): category = input("Enter a category: ") example = "" for j in range(3): example += input("Enter something in that category: ") print(category+ ": " + example)

5.2.9: How Many Names?

full_name = "" number_of_names = int(input("How many names do you have? ")) for i in range(number_of_names): next_name = input("Enter a name: ") full_name = full_name + next_name + " " print (full_name)

5.3.8: Higher / Lower 2.0

magic_number = 3.3312 while True: user_number = float(input("Enter a number between 1 and 100: ")) if round(user_number, 2) == round(magic_number, 2): print ("Correct!") break elif round(user_number,2) > round(magic_number, 2): print ("Too high!") else: print ("Too low!")

5.1.7: Divisibility

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")


Related study sets

Psych Prep U Anger, Hostility, and Aggression

View Set

HUSH WWII Vocab (singapore side)

View Set

BNAD 303 Chapter 16 MIndtap Questions

View Set

Mean Absolute Deviation, Mean Absolute Deviation terms

View Set

EatRight Prep RD Exam Study Cards

View Set

Accounting Chapter 5: Receivables and Sales

View Set

Chapter 13: Fluid and Electrolytes: Balance and Disturbance

View Set

Geriatrics Chapter 19: Falls and Fall Risk Reduction

View Set