Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions guesser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@

def main():
attempts = 1 # Initial count of attempts. Minimum is 1.
print "How many numbers do you want?"
print( "How many numbers do you want?")
# Declare variable to generate random number inside range.
howMany = input("Ammount: ")
howMany = int(input("Ammount: "))
if howMany == 1:
print "Pick a number greater than 1!"
print( "Pick a number greater than 1!")
main() # If the number is 1, return to main.

else: # if the number is greater than 1, continue.
print 'Guess the number between 1 and {}.'.format(howMany)
print('Guess the number between 1 and {}.'.format(howMany))
randomNumber = random.randint(1, howMany)

found = False # declare found as false.

while not found: # while the user has not guessed the correct number.

userGuess = input("Your guess: ")
userGuess = int(input("Your guess: "))
if userGuess == randomNumber:
print "You have guessed the correct number! You used", attempts, "attempts."
print("You have guessed the correct number! You used", attempts, "attempts.")
found = True # declare found as true which ends the program

elif userGuess > randomNumber: # if the user is less than the generated number
print ("Guess lower!")
print ("Guess higher!")
attempts = attempts + 1 # add one attempt to the counter
else:
print ("Guess higher!")
print ("Guess lower!")
attempts = attempts + 1 # add one attempt to the counter


Expand Down