Python Forum
Name guessing game in python
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Name guessing game in python
#1
Hey guys so I am having some trouble with the second part of a program that I need to write 

So the first part was to write a number guessing game in which the user has a limited number of tries to guess the number between 1 and 10 in which I have managed to do but now we have to alter the code so it can Write a program that asks the user to guess your name using a while loop. I need to repeatedly ask the user for a name and when they input your name e.g John, it displays "Got it" and stops looping.  if it's not your name it outputs "Guess again".


Also it has to be able to handle input in upper and lower case.


So far my number guessing game is looking like this.
import random

print("\tWelcome to 'Guess My Number'!")
print("\nI'm thinking of a number between 1 and 10.")
print("Try to guess it in as few attempts as possible.\n")

# set the initial values
the_number = random.randint(1, 10)
guess = int(input("Take a guess: "))
tries = 1

# guessing loop
while guess != the_number:
    if guess > the_number:
        print("Lower...")
    else:
        print("Higher...")

    guess = int(input("Take a guess: "))
    tries += 1
    if tries == 6:
        print ("You failed to guess in time!")
        break
    if guess == the_number:
        print("You guessed it! The number was", the_number)
        print("And it only took you", tries, "tries!\n")
So far I have something like this that is very basic
name = ''

while name != 'Kate':
    print('What is my name?')
    name = input()

print('Yes, My name is ' + name + '. Congratulations')
Also I have managed to modify it somewhat. I am just confused to why when you guess the correct name it wont print Got it instead of Try again...

name = ''

while name != 'Kate':
    print('What is my name?')
    name = input()
if input == name:
    print("Got it")
else:
    print("Try Again")
Output:
What is my name?
Jack
What is my name?
John
What is my name?
Kate
Try Again

Process finished with exit code 0
Probably something quite simple I am missing here lol
Reply


Messages In This Thread
Name guessing game in python - by Liquid_Ocelot - Apr-01-2017, 07:44 AM
RE: Name guessing game in python - by Ofnuts - Apr-01-2017, 08:03 AM
RE: Name guessing game in python - by Liquid_Ocelot - Apr-01-2017, 08:12 AM
RE: Name guessing game in python - by Liquid_Ocelot - Apr-01-2017, 10:26 AM
RE: Name guessing game in python - by ichabod801 - Apr-01-2017, 10:51 AM
RE: Name guessing game in python - by Liquid_Ocelot - Apr-01-2017, 10:58 AM
RE: Name guessing game in python - by ichabod801 - Apr-01-2017, 12:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Play again, in a guessing game banidjamali 4 11,749 Jan-22-2021, 06:23 AM
Last Post: banidjamali
  Help - random number/letter guessing game juin22 1 3,209 Aug-16-2020, 06:36 AM
Last Post: DPaul
  making a guessing number game blacklight 1 2,207 Jul-02-2020, 12:21 AM
Last Post: GOTO10
  Guessing game with 4 different digits LinseyLogi 6 3,661 Mar-29-2020, 10:49 AM
Last Post: pyzyx3qwerty
  Guessing game with comparison operators Drone4four 9 13,808 Dec-02-2018, 06:12 PM
Last Post: ichabod801
  Guessing Game "limit 4 attempts" help rprollin 3 19,774 Jun-23-2018, 04:37 PM
Last Post: ljmetzger
  guessing script simon 3 5,592 Oct-10-2016, 01:47 PM
Last Post: simon
  trying to get my random number guessing game to work! NEED HELP RaZrInSaNiTy 4 6,898 Oct-06-2016, 12:49 AM
Last Post: tinabina22

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020