+ 1
Can this be modified using "else/elif" code in anyway way???
My First Code EVER!!! y = int(2017) - int(input("Enter your birth year:")) print('\nYou\'re') print(y) print('Years Old.') if y >= 20: print('You are no longer a teenager but an adult.') if y <= 19 and y >=13: print('You are a teenager') if y <=12: print('You are a kid')
7 Réponses
+ 11
Hmm, as far as I can see, your conditional statements do not overlap with each other. Hence methinks it is unnecessary to use elif.
+ 11
also using int is unnecessary on constants:
just write 2017 - something
+ 8
you can write
if age >= 20:
elif age >= 13:
else:
And tour code between them
+ 6
Tip:
In Python, you can write: '13 <= y <=19' instead of 'y >= 13 and y <= 19' ;)
+ 2
Yes, you need rewrite your last 2 if'es
Use elif, check your code
0
I rewrote it like this:
y = 2017 - int(input("Enter the birth year:"))
print("\nYou\'re",y,"years old.")
if y <= 12:
print("You are a kid.")
elif y >= 13 and y <= 19:
print("You are in your teens.")
elif y >= 20:
print("You have stepped into adulthood now.")
0
Thanks visph... Awesome tip!!!