While loop

user = input ("") user = True user = False while True: print("I know you are, but who am I?") break continue user = input("") while False: break print ("bye") I need help with this code I am writing this program in Python that responds I know who you are, but what am I? whenever the user enters a value using input This should continue unless the user enters nothing at all, in which case the program should print out "Bye" and stop. I’m stuck https://code.sololearn.com/ccnI0V3E8O8Y/?ref=app

4th Feb 2023, 12:23 AM
Karl π
Karl π - avatar
4 Answers
+ 3
# Hi, Karl π ! # Here’s another approach: count = 0 try: while True: print(f"<Loop: {count}>") print("I know who you are, " "but who am I?") user = input("> ") print(repr(user), "\n") if not user: raise ValueError print(f"\t-> An inputed name!") print("\t... so the program" " goes on...\n") count += 1 except ValueError: if not count: print("\t<There was no input " "at all!>\n") print("Bye!") except EOFError: print(f"\t<There was no more " "inputs...>") finally: print("\n\t-> Program end!") # https://code.sololearn.com/c6ReB3X435o7/?ref=app
4th Feb 2023, 11:45 AM
Per Bratthammar
Per Bratthammar - avatar
4th Feb 2023, 12:42 AM
SoloProg - avatar
+ 1
Here you have a solution that should do what you expect i modified a bit https://code.sololearn.com/cWgHbXUOvioQ/?ref=app
4th Feb 2023, 1:08 AM
S3R43o3 - avatar
+ 1
Per Bratthammar hehe yeah dude thats the clean version 😋👌
5th Feb 2023, 10:56 AM
S3R43o3 - avatar