Skip to content

Instantly share code, notes, and snippets.

@charleyXuTO
Last active March 25, 2016 02:40
Show Gist options
  • Select an option

  • Save charleyXuTO/7211bd182b858c855540 to your computer and use it in GitHub Desktop.

Select an option

Save charleyXuTO/7211bd182b858c855540 to your computer and use it in GitHub Desktop.

Revisions

  1. charleyXuTO renamed this gist Mar 25, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. charleyXuTO created this gist Mar 25, 2016.
    28 changes: 28 additions & 0 deletions guessTheNumber
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    import random

    guessesTaken=0

    myname=input("Hello! What is your name?")

    number=random.randint(1,20) #The number that the user needs to guess
    print('Well, ' +myname+ ', I am thinking of a number between 1 and 20. You have 5 tries to guess the number. Good luck! :)')

    while guessesTaken<6:
    guessed_number=int(input("Guess a number!")) #User inputs here
    if guessed_number==number:
    print("Good job! You guessed my number!")
    break
    if guessed_number>number:
    print("Nope. Sorry. The number is lower.")
    if guessed_number<number:
    print("Nope. Sorry. The number is higher.")

    guessesTaken=guessesTaken+1



    if guessed_number != number:
    print("Sorry, my number was " + str(number))


    print("Thanks for playing!")