From a8239fb2b9578ffc5bd248610a521834a62e3602 Mon Sep 17 00:00:00 2001 From: MattySly <44401806+MattySly@users.noreply.github.com> Date: Thu, 25 Oct 2018 15:38:04 -0700 Subject: [PATCH] greater than 10 or less than 1 added if statements for when the user guesses greater than 10 or less than 1. --- guessinggame.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/guessinggame.py b/guessinggame.py index 141ce11..560fc07 100644 --- a/guessinggame.py +++ b/guessinggame.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +# !/usr/bin/env python3 import random @@ -6,14 +6,13 @@ 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") @@ -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))