Mar-25-2018, 09:10 AM
(This post was last modified: Mar-25-2018, 09:13 AM by orangevalley.)
[font=Times New Roman, Times, serif]
I am new at python and i'm trying to teach myself the best way i can. So i will make noob mistakes. I was wondering if you could tell me where my code is going wrong and how i could improve it?
I have been trying to make a simple age calculator as part of the questions i have recieved at school.
The question is:
Write a program that asks the user to enter their age (in years).
- If the user is 100 or older, tell them You've already turned 100!.
- If they are less than 0, tell them Try again after you are born!.
- If neither of these cases apply, calculate the number of years before they turn 100 and output the message You will be 100 in x years! (where x is - replaced by the number of years before they turn 100).
- You must use an if...elif...else statement for this problem.
my code
I am new at python and i'm trying to teach myself the best way i can. So i will make noob mistakes. I was wondering if you could tell me where my code is going wrong and how i could improve it?
I have been trying to make a simple age calculator as part of the questions i have recieved at school.
The question is:
Write a program that asks the user to enter their age (in years).
- If the user is 100 or older, tell them You've already turned 100!.
- If they are less than 0, tell them Try again after you are born!.
- If neither of these cases apply, calculate the number of years before they turn 100 and output the message You will be 100 in x years! (where x is - replaced by the number of years before they turn 100).
- You must use an if...elif...else statement for this problem.
my code
1 2 3 4 5 6 7 8 9 10 11 12 |
age = int ( input ( "Enter your current age in years: " )) if (age > = 100 ): print ( "You've already turned 100!." ) elif : for age in range ( 0 > - 100 :) print ( "Try again after you are born!." ) else : x = ( int (age - 100 )) print ( "You will be 100 in" x "years!" ) |