It's a very rudimentary question...crying

Asked 2 years ago, Updated 2 years ago, 29 views

I'm a beginner who just started Python. I don't think I understand.


age = input ("Please enter your age")

print ("Your age is %s".")

if age <= 19:

    print ("You're Minors")

else :
    print ("You're an adult")

If you're under 19 after you get your age, you're a minor Other than that, I want to write as an adult I keep getting errors. Could you tell me what you typed wrong?

python

2022-09-22 18:18

1 Answers

age = input ("Enter your age")

where input stores the entered value in str, i.e. age as a string.

Therefore, int 19 and str 19 stored in age have different data types

The conditional expression does not hold.

So in front of the input, the data type is an integer type

You have to write int(), which is a function that you want to.

age = int("Enter your age")

print ("Your age is %s." %age)

if age <= 19:

    print ("You're Minors")

else :
    print ("You're an adult")


2022-09-22 18:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.