jeudi 20 août 2020

Beginner question. Why is this not working? (Python) Thanks 😊

import random

def restart() :
    print(" ")
    print("Do you want to play again?")                              
    goAgain = str(input())
    if goAgain == "yes" :
        guessingGame()
    elif goAgain == "no" :
        print(" ")
        print(":(")
        print(" ")
    else :
        print ("(yes or no)")

def guessingGame() :
    num = random.randint(1, 10)
    print(" ")
    print("Guess a number, it's between 1 and 10")
    guess = int(input())
    while num != "guess":
        if guess < num:
            print ("Too low, try again")
            guess = int(input( ))
        elif guess > num: 
            print ("Too high, try again")
            guess = int(input())
        else:
            print(" ")
            print ("Well done, you guessed correctly!")
            print(" ")
            restart()
        
guessingGame()

Aucun commentaire:

Enregistrer un commentaire