dimanche 22 novembre 2015

How do I make my program check whether user input is within 5,10,15,20, etc of the random integer?

import random

print("Pick a number from 1-50")

randomNumber = random.randint(1,50)
correct = False

while not correct:
    try:
        userInput = int(input("Insert your number here. "))
    except ValueError:
        print("That is not a Number!")
        continue
    if userInput > randomNumber:
        print("Guess lower.")
    elif userInput < randomNumber:
        print("Guess Higher.")
    else:
        print("You got it!")
        break

So this code currently takes the user input and says whether the user guessed the random integer, or if they should guess higher/lower. I want to edit the code to now say whether the user input is within 5,10,15, etc of the random integer.

So if the random integer was 30, and the user inputs 20, the program would say something like "You are within 10; guess higher."

Any advice? I'm extremely new to python, so please respond with more simple methods if possible.

Thanks.




Aucun commentaire:

Enregistrer un commentaire