Solved! Thanks tdelaney, your repr tip helped a lot and John Kugelman you called it as I was typing this! Thanks to everyone for being so quick to respond!
I was including a space when prompted for my favorite color ex. What is your favorite color? Blue
I edited my if A == 'Blue' to if A == ' Blue' or A == 'Blue' with both cases
from random import randint
# Establish the lower and uppper bound on the goal number
MINIMUM = 1
MAXIMUM = int(input("State a number"))
def print_welcome():
'''
Prompt the user for their name, and then display a
simple message explaining the rules of the game.
'''
# Get the name of the user
if MAXIMUM < 10:
print("Too easy, you bore me!")
else:
print("BAHAHA A REAL CHALLENGER EH?")
name = input("What is your name? ")
# Show the user's name
input("What is your quest?")
A = input('What... Is your favorite color?')
if A == 'Blue' or A == 'blue':
print("You get thrown off a bridge")
else:
print("Right, on you go then!")
print("Just kidding", name, "!", "...welcome to my guessing game.")
# Print out the limits of the goal number
print("I've thought of a number between", MINIMUM, "and", MAXIMUM)
# Write out rest of the instructions
print("You need to guess that number.")
print("I'll tell you if you need to go higher or lower.")
def print_ending():
'''
Print out a conclusive message to wrap up the game.
'''
print("You win!")
def process_guess(guess, goal):
'''
Print out whether or not the user was above, below,
or at the goal.
Args:
guess (int): The number that the user entered
as their guess.
goal (int): The number that the computer is
thinking of.
'''
# Branch execution based on whether the guess was right
if guess < goal:
print("You need to go higher!")
elif guess > goal:
print("You need to go lower!")
else:
print("That's correct, it's", goal)
def get_number():
'''
Ask the user for a number, and keep prompting
them until they give you an actual number
(as opposed to giving you a letter).
'''
# Get the guess from the user, returns a string
number = input("What is your guess? ")
# Was the string composed only of numbers?
if number.isdigit():
# If so, we can safely convert it to an integer
number_as_int = int(number)
# And return the result
return number_as_int
else:
# Otherwise, call this function again recursively
return get_number()
def main_game():
'''
Play a round of the game.
'''
# Pick random number between MINIMUM and MAXIMUM
goal = randint(MINIMUM, int(MAXIMUM))
# Initially, the user hasn't guessed anything.
user_guess = None
print_welcome()
# Repeatedly ask the user until they get it right
while user_guess != goal:
user_guess = get_number()
process_guess(user_guess, goal)
print_ending()
# This if statement is common in most professional Python
# programs - don't worry too much about what it does,
# but you can safely assume it will work when you press
# the run button.
if __name__ == '__main__':
main_game()
This is just a small cut out of a game I am making for a class. If you look at the last four lines, every time I input the "blue" answer it skips the print("You get thrown off a bridge"). I do not think it is registering the answers that I want the code to recognize.
edit: I have added the complete code. the def print_welcome() portion at the beginning is the only area giving me the issue listed above.
sorry for not including the complete code initially as this is the first time I have posted a question on here and did not know what I should have included.
As I stated before, this is for a class. The assignment is to alter an already established code to give it some personal flavors.
Aucun commentaire:
Enregistrer un commentaire