import random
number = random.randint(1, 10)player_name = "doo"
number_of_guesses = 0
print('I\'m glad to meet you! {} \nLet\'s play a game with you, I will think a number between 1 and 10 then you will guess, alright? \nDon\'t forget! You have only 3 chances so guess:'.format(player_name))while number_of_guesses < 3:guess = int(input())number_of_guesses += 1if guess < number:print('Your estimate is too low, go up a little!')if guess > number:print('Your estimate is too high, go down a bit!')if guess == number:break
if guess == number:print( 'Congratulations {}, you guessed the number in {} tries!'.format(player_name, number_of_guesses))
else:print('Close but no cigar, you couldn\'t guess the number. \nWell, the number was {}.'.format(number))
Above is the Guess the number project using input.
I want to make it without input.
Can't we use a list or variable to make it?
So I tried.
import random
list=[1, 2, 3, 4, 5, 8, 9, 10]
print('I am Guessing a number between 1 and 10:\n')
for number in lis:number_of_guesses = 0while number_of_guesses<3:guess_number=random.randint(1,10)if number<guess_number:number_of_guesses+=1print('Your guess number is high '+str(guess_number))elif number>guess_number:number_of_guesses+=1print('Your guess number is low '+str(guess_number))else:print("You guess Right The number is: "+str(guess_number)+"\nNumber of guess taken "+str(number_of_guesses+1))breakif number_of_guesses==3:print("Sorry your chances of guessing is over! You can not guess the number correct")
Failed to create Guess the number code without input.
Help me.