#๐ sm1 help me
30 messages ยท Page 1 of 1 (latest)
@silent grove
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
def get_age():
while True:
try:
age = int(input("Type your age: "))
if 18 <= age <= 100:
return age
else:
print("Please enter a valid age.")
except ValueError:
print("Please enter a number.")
def try_again():
while True:
answer = input("Do you want to try again? (y/n): ").strip().lower()
if answer in ['y', 'n']:
return answer = 'y'
else:
print("Please enter 'y' for yes or 'n' for no.")
def main():
while True:
age = get_age()
if age >= 18:
print("You are eligible.")
else:
print("You are not eligible.")
if not try_again():
print("Goodbye!")
break
if name == "main":
main()
under what circumstances would it print "You are not eligible"? The question in get_age() does not allow any answers under 18
its just a test bro chill[
What loader? Right now your code won't run at all because if name == "main" is incorrect. For a proper entry point to your application when running it as a main script, use if __name__ == "__main__" instead. You will also get a syntax error for return answer = y in the try_again function, should just be return answer. After you fix these issues your code should at least run.
ty
the snippet isn't formatted properly for discord; the user does have underlines there
Ah, that always gets me that they disappear when not formatted properly.
def get_age():
while True:
try:
age = int(input("Type your age: "))
if 18 <= age <= 100:
return age
else:
print("Please enter a valid age.")
except ValueError:
print("Please enter a number.")
def try_again():
while True:
answer = input("Do you want to try again? (y/n): ").strip().lower()
if answer in ['y', 'n']:
return answer = 'y'
else:
print("Please enter 'y' for yes or 'n' for no.")
def main():
while True:
age = get_age()
if age >= 18:
print("You are eligible.")
else:
print("You are not eligible.")
if not try_again():
print("Goodbye!")
break
if __name__ == "__main__":
main()
ftfy
return answer = 'y' is still invalid syntax I believe
yes
actually no lmao
no?
returning an assignment is definitely a syntax error
how did your editor not tell you that
the editor just gave me an error on 17
what's on line 17?
but did not said me it was =
the "= 'y'"
well you said "no" when @urban agate said it was invalid syntax
so what is it that you need from us?
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.