0
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
4 Réponses
+ 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
+ 1
Hope this helps
https://code.sololearn.com/c0VMyXRhJ6SQ
+ 1
Here you have a solution that should do what you expect i modified a bit
https://code.sololearn.com/cWgHbXUOvioQ/?ref=app
+ 1
Per Bratthammar hehe yeah dude thats the clean version 😋👌