Enviado em 01/07/2016 - 19:09h
Sou bem iniciante em python e retomei meus estudos (apesar de não ser da área). Vi um game de guesses e repliquei, porém adicionei o while no final do código para jogar continuamente, porém (apesar das diversas tentativas de mudar o código) ele só executa duas vezes e não infinitamente como eu gostaria.#!/usr/bin/python3
import random
import sys
print("What is your name")
name = input()
print("Hello "+ str(name))
print ('I have a trick question for you, now I thinking in a number betwen 0 and 20. guess the number')
def guesses(play):
guessTaken = 0
mynumber = random.randint(0,20)
while guessTaken < 3:
print ('Take a guess:')
guess = input()
guess = int(guess)
guessTaken = guessTaken+1
if guess < mynumber:
print("Number is too low :P")
if guess> mynumber:
print("Number is too high. Guess again! <3")
if guess == mynumber:
break
if guess == mynumber:
print("Guess taken "+ str(guessTaken))
print("Good job ")
print( "Do you wanna play again? Press 1")
again = input()
return again
if guess != mynumber:
print(str(guessTaken)+"it's enough")
print("The number was "+" "+str(mynumber))
print( "Wanna play again ? Press 1")
again = input()
return again
play= 1
guesses(play)
play = guesses(play)
while guesses(play) == 1:
guesses(play)