Solution for python code plssssss


#1

You have to guess a number between 1 to 10 up to three times. My code works if the user doesn’t guess correctly but there’s an error message if the user guesses it correctly.

code:

from random import randint

Generates a number from 1 through 10 inclusive

random_number = randint(1, 10)

guesses_left = 3

Start your game!

while guesses_left > 0:
guess = int(raw_input("Your Guess: "))
guesses_left -= 1
if guess == random_number:
print "You win!"
break
else:
print “You lose.”

error message:

Your Guess: 2
Your Guess: 2
Your Guess:
Traceback (most recent call last):
File “python”, line 10, in
ValueError: invalid literal for int() with base 10: ‘’


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.