Advertisement
ZEdKasat

While loop assignment 3

Sep 20th, 2021 (edited)
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import random
  2. result = False # condition variable that keeps us inside the while loop
  3.  
  4. while not result: # while condition variable is not True
  5.     num = random.randrange(1000, 9999) # generating a random number between given numbers
  6.     user_answer = input("Do you think", num, "is divisible by 13? yes or no?") # getting input from the user in yes or no (Lowercase yes is necessary)
  7.  
  8.     if user_answer == "yes" and num % 13 == 0: # check if response is yes and number is also divisible by 13
  9.         result = False # if yes, set the condition variable from while loop to True
  10.     else:
  11.         print("Incorrect answer, lets try that again :)") # if answer is wrong we don't update the condition variable and program stays inside the loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement