I'm trying to find a way to access the confirmpath()
function in the pathcond()
function. Please help.
PS. I just began learning Python about a week ago, so any help regarding my code brevity and improving my overall skills will be really appreciated.
Following is the code I need help with:
def name():
global call
call = raw_input("What is your name?\n")
print("Hello " + call)
def game():
global charchoose
charchoose = raw_input("What will be your character " + call + ": Mage, Wizard or Knight?\n")
print("You chose " + charchoose)
def path():
pathchoose = raw_input("You are a " + charchoose + " who was walking down Tranversia and came across a three-way road. Which on will you choose? Land, Sea or Clouds\n").lower()
def confirmpath():
global confirmpath
confirmpath = raw_input("You chose " + pathchoose + ". Are you sure you want to continue? Yes or No?\n").lower()
pathcond()
confirmpath()
def pathcond():
while confirmpath == "no":
path()
if confirmpath == "yes":
print("Good choice, you win!")
else:
print("Sorry, we didn't get that. Can you answer again, please?")
confirmpath()
def ask():
askplay = raw_input("Would you like to play a game? Yes or No?\n").lower()
if askplay == "yes":
game()
path()
elif askplay == "no":
print("That's alright. Thanks for hanging out, though. Bye!")
else:
print("Sorry, I didn't get that. Please try again.")
ask()
name()
ask()
UPDATE: I worked further on the program for sometime and ended up with a version that is now problem free. I've posted it below, please help me make it better by suggesting what I could change/improve/remove. The code is as follows:
def Initiate():
global call
call = raw_input("What is your name?\n")
print("Hello " + call)
begin()
def game():
global charchoose
charchoose = raw_input("What will be your character " + call + ": Mage, Wizard or Knight?\n")
print("You chose " + charchoose)
path()
def path():
global pathchoose
pathchoose = raw_input("You are a " + charchoose + " who was walking down Tranversia and came across a three-way road. Which on will you choose? Land, Sea or Clouds\n").lower()
confirmpath()
def confirmpath():
global confirmpaths
confirmpaths = raw_input("You chose " + pathchoose + ". Are you sure you want to continue? Yes or No?\n").lower()
pathcond()
def pathcond():
while confirmpaths == "no":
path()
if confirmpaths == "yes":
print("Good choice, you win!")
else:
print("Sorry, we didn't get that. Can you answer again, please?")
confirmpath()
def begin():
askplay = raw_input("Would you like to play a game? Yes or No?\n").lower()
if askplay == "yes":
game()
elif askplay == "no":
print("That's alright. Thanks for hanging out, though. Bye!")
else:
print("Sorry, I didn't get that. Please try again.")
ask()
Initiate()
UPDATE 2: The code functions properly but still ends up printing the following string numerous times
if confirmpaths == "yes":
print("Good choice, you win!")
I observed that it prints the string as many times as I reply to the confirmpath()
function, regardless of whatever my response is.