+ 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')

21st Feb 2017, 8:15 AM
Aaqib Bhat
7 Respuestas
+ 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.
21st Feb 2017, 8:18 AM
Hatsy Rei
Hatsy Rei - avatar
+ 11
also using int is unnecessary on constants: just write 2017 - something
21st Feb 2017, 8:29 AM
WittyBit
WittyBit - avatar
+ 8
you can write if age >= 20: elif age >= 13: else: And tour code between them
21st Feb 2017, 8:28 AM
WittyBit
WittyBit - avatar
+ 6
Tip: In Python, you can write: '13 <= y <=19' instead of 'y >= 13 and y <= 19' ;)
21st Feb 2017, 8:53 AM
visph
visph - avatar
+ 2
Yes, you need rewrite your last 2 if'es Use elif, check your code
21st Feb 2017, 8:18 AM
Leshark
Leshark - avatar
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.")
21st Feb 2017, 8:44 AM
Aaqib Bhat
0
Thanks visph... Awesome tip!!!
21st Feb 2017, 9:00 AM
Aaqib Bhat