![]() |
Hello need some help with some code! - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Hello need some help with some code! (/thread-17717.html) |
Hello need some help with some code! - GalaxyCoyote - Apr-21-2019 Hello, I am new to python (I have just started learning a week ago) and I need some help with this name_program = input("Please enter you name: ") age_program = input("Please enter your age:" ) country_program = input("Please enter you location: ") print("Hello " + name_program + " so your " + age_program + " years old?") yes_no_program = input("yes or no?") if yes_no_program == "yes": print("Wow that's great") else: age_program = input("Then what is it again?") print("anyways") print("so you come from " + country_program + " heard it's a nice place")The idea is that if you respond yes to yes_no_program then it goes through to the next part but if you respond with anything else then it will repeat the age question. Sorry for any sloppy coding and sorry if the answer is obvious. RE: Hello need some help with some code! - ichabod801 - Apr-21-2019 First, make sure line 8 is indented the same as line 6 and that line 9 is indented the same as line 7. Maybe that's a copy and paste error, but the code as posted won't work. Next, indent the first 9 lines under a while True: loop. Add a break statement after line 7, to get out of the loop when they confirm the answer.
RE: Hello need some help with some code! - Yoriz - Apr-21-2019 Hey The area you are joining strings and variable can be replaced with f strings see below. To get a loop, a while loop can be used that when a condition is met it will break out of the loop. name_program = input("Please enter you name: ") age_program = input("Please enter your age:" ) country_program = input("Please enter you location: ") # print("Hello " + name_program + " so your " + age_program + " years old?") while True: print(f"Hello {name_program} so your {age_program} years old?") yes_no_program = input("yes or no?") if yes_no_program == "yes": print("Wow that's great") break else: age_program = input("Then what is it again?") print("anyways") # print("so you come from " + country_program + " heard it's a nice place") print(f"so you come from {country_program} heard it's a nice place") RE: Hello need some help with some code! - SheeppOSU - Apr-21-2019 you should use a functions like this - def name(): name_program = input("Please enter you name: ") return name_program def age(repeat): if not repeat: age_program = input("Please enter your age: " ) return age_program else: age_program = input("Then what is it again? " ) return age_program def country(): country_program = input("Please enter you location: ") return country_program def Main(): name_program = name() age_program = age(False) print("Hello " + name_program + " so your " + age_program + " years old?") while True: yes_no_program = input("yes or no? ") if yes_no_program == "yes": print("Wow that's great") break elif yes_no_program == "no": age_program = age(True) print("Hello %s, so your %s years old" %(name_program, age_program)) print("anyways") country_program = country() print("so you come from " + country_program + " heard it's a nice place") Main() RE: Hello need some help with some code! - GalaxyCoyote - Apr-21-2019 (Apr-21-2019, 05:22 PM)Yoriz Wrote: Hey Thanks for helping! |