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
21 changes: 13 additions & 8 deletions guessinggame.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#!/usr/bin/env python3
# !/usr/bin/env python3

import random

number = random.randint(1, 10)
tries = 0
win = False # setting a win flag to false

name = input("Hello, what is your username? ")

name = input("Hello, What is your username?")

print("Hello" + name + "." )
print("Hello", name + ".", )

question = input("Would you like to play a game? [Y/N] ")
if question.lower() == "n": #in case of capital letters is entered
print("oh..okay")
if question.lower() == "n":
print("Have a nice day")
exit()
if question.lower() == "y":
print("I'm thinking of a number between 1 & 10")
Expand All @@ -22,10 +21,16 @@
tries = tries + 1
if guess == number:
win = True # set win to true when the user guesses correctly.
elif guess > 10:
print("Learn to count to 10")
exit()
elif guess < 1:
print("Learn to count to 10")
exit()
elif guess < number:
print("Guess Higher")
elif guess > number:
print("Guess Lower")
# if win is true then output message
print("Congrats, you guessed correctly. The number was indeed {}".format(number))
print("it had taken you {} tries".format(tries))
print("Congrats", name + ",", "you guessed correctly. The number was indeed {}.".format(number))
print("It only took {} tries.".format(tries))