mercredi 6 avril 2016

rando guessing game in python

My code was working fine, and then I tried to add in a function which is causing me some issues. Keep in mind that this is for school. Suggestions would be helpful, thanks!

import random

easy = random.randint (1,20)
medium = random.randint (1,50)
hard = random.randint (1,100)
guessesTaken = 0

name = input("Hello, What is your name? ")

def difficulties():
    difficulty = input("Well, ",name,". What dificulty would you like ?       easy, medium, or hard? ")
    if difficulty == "easy":
        number = easy
        print ("Okay, ",name,". I am thinking of a number between 1 and 20")
    if difficulty == "medium":
        number = medium
        print ("Okay, ",name,". I am thinking of a number between 1 and 50")
    if difficulty == "hard":
        number = hard
        print ("Okay, ",name,". I am thinking of a number between 1 and  100")

difficulties()

while guessesTaken < 6:
    guess = int(input('Take a guess. ')) 
    guessesTaken = guessesTaken + 1

    if guess < number:
        print("Your guess is too low.") 

    if guess > number:
        print("Your guess is too high.")

    if guess == number:
        break

if guess == number:
    guessesTaken = str (guessesTaken)
    print("Good job, ",name," ! You guessed my number in ",guessesTaken," guesses, good job!")

if guess != number:
    number = str (number)
    print("Nope. The number I was thinking of was ",number,", better luck next time!")




Aucun commentaire:

Enregistrer un commentaire