#๐Ÿ”’ sm1 help me

30 messages ยท Page 1 of 1 (latest)

silent grove
#

the loader is not loading so umm

uneven treeBOT
#

@silent grove

Python help channel opened

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.

silent grove
#

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()

glad owl
#

under what circumstances would it print "You are not eligible"? The question in get_age() does not allow any answers under 18

silent grove
#

its just a test bro chill[

urban agate
# silent grove the loader is not loading so umm

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.

glad owl
urban agate
glad owl
#
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

urban agate
glad owl
#

yes

silent grove
glad owl
#

no?

silent grove
#

not a string

glad owl
#

returning an assignment is definitely a syntax error

urban agate
silent grove
#

the =

#

its ==

glad owl
#

how did your editor not tell you that

silent grove
#

the editor just gave me an error on 17

glad owl
#

what's on line 17?

silent grove
#

but did not said me it was =

silent grove
glad owl
#

well you said "no" when @urban agate said it was invalid syntax

#

so what is it that you need from us?

uneven treeBOT
#
Python help channel closed for inactivity

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.