0
from fileinput import close

from random import Random, random

print('Do you want to play a game?')
input1 = input("yes or no? ")
if input1 == "yes" or input1 == "Yes":
    print("You have 3 tries to guess a random integer between 0-10. If you guess right 
you win. If not I do. Ready?")
import random
def repeat():

    number = random.randint(1,10)
    print(number)
    guess1 = input('Your first guess: ')
    if guess1 == number:
        print('You are correct! You only needed one try!')
    else:
        print('Wrong two tries left!')
        guess2 = input('Your second guess: ')
    if guess2 == number:
        print('You are correct! You needed two tries!')
    else:
        print('Wrong one try left!')
        guess3 = input('Your third and last guess: ')
    if guess3 == number:
        print('You are correct! It took you all three tries!')
    else:
        print('You are wrong! You lost! The number was:')
        print(number)
        input2 = input('Do you want to play again? Yes or No? ')
        if input2 == 'Yes' or 'yes':
            repeat()
        else:
            close()

else: close() repeat()

I have no clue where the mistake is, but when I guess number correctly it still says its wrong.

1 Answers1

0

You need to convert all guesses into integers to compare since the default input type is string.

from fileinput import close
from random import Random, random

print('Do you want to play a game?')
input1 = input("yes or no? ")
if input1 == "yes" or input1 == "Yes":
    print("You have 3 tries to guess a random integer between 0-10. If you guess right you win. If not I do. Ready?")
import random
def repeat():

    number = random.randint(1,10)
    print(number)
    guess1 = int(input('Your first guess: '))
    if guess1 == number:
        print('You are correct! You only needed one try!')
    else:
        print('Wrong two tries left!')
        guess2 = int(input('Your second guess: '))
    if guess2 == number:
        print('You are correct! You needed two tries!')
    else:
        print('Wrong one try left!')
        guess3 = int(input('Your third and last guess: '))
    if guess3 == number:
        print('You are correct! It took you all three tries!')
    else:
        print('You are wrong! You lost! The number was:')
        print(number)
        input2 = input('Do you want to play again? Yes or No? ')
        if input2 == 'Yes' or 'yes':
            repeat()
        else:
            close()
else: close() repeat()
Misaka
  • 146
  • 5