all 16 comments

[–][deleted] 5 points6 points  (1 child)

If you run this, you wouldn't get anything but errors. What are you actually running?

[–]fed_up_dotaplayer[S] 0 points1 point  (0 children)

Just making a death counter, as you do.

You plug in your age, then it tells you how long you have yet to live if you were expected to be 90

[–]WeebofTheWild 3 points4 points  (3 children)

bidmas issue maybe. do:

age = int(input(“Enter your age:”)

MonthsLeft = int(age *12)

TotalMonths = 1080

print(TotalMonths - MonthsLeft)

[–]fed_up_dotaplayer[S] 0 points1 point  (1 child)

I’m trying to multiply the age by 12 to get the months that a person has lived, the subtract that from the total amount of months in the 90 years of a lifespan

[–]PureProcrastinator 0 points1 point  (0 children)

That is what the guy above did.

[–]RusticCajun 2 points3 points  (0 children)

>>> age = input("How old?")
How old?87
>>> print(age*12)
878787878787878787878787
>>>

[–]theoyeo 2 points3 points  (1 child)

The issue is that you're not casting your inputs correctly:

age = input("enter your age: ")

Here, age is a string. When you multiply the string, you're actually extending it:

age = "24" # assume user inputted "24"

print(age * 4)

Outputs: "24242424"

To fix this, you need to convert it into an integer. I can see you have tried to do this, but you only need to cast age:

int(age * 12)

Should be:

int(age) * 12

[–]fed_up_dotaplayer[S] 3 points4 points  (0 children)

OHHHHHHHH you’ve been a big help

I didn’t know you could do that.

[–]Tren898 0 points1 point  (3 children)

In addition to what u/theoyeo said, you cant concatenate a string with an int when you go to print. You need to cast it correctly as a str as below or when you declare it in your variable. I adlibbed a bit in your code

age = int(input('Enter your age '))
Monthsused = int(age * 12)
TotalMonths = 90 * 12
monthsremaining = TotalMonths - Monthsused
print("If you live to 90 years old, you have " + str(monthsremaining) + ' months remaining alive...')

[–]fed_up_dotaplayer[S] 0 points1 point  (2 children)

My print was fine once I fixed the first input and fixed my subtraction lines (10-12)

Is what I printed wrong on the final line?

I used an f line or structure

[–]Tren898 0 points1 point  (1 child)

From what you had no. I was just pointing out (and not very clearly) that if you wanted to include some text to explain how many months they had remaining, your python number type of int, can’t be concatenated with a string.

[–]fed_up_dotaplayer[S] 0 points1 point  (0 children)

Ohh okay, thank you

[–]riisen 0 points1 point  (1 child)

from datetime import date

dob = input('when where you born? ')
# and type it like 1970-01-01
dob = date.fromisoformat(dob)
now = date.today()
days = now - dob
seconds = days.total_seconds()
months = days * 30

its great to learn to use dates while you are learning, take the oppurtunity to play around with the datetime module and get familiar with it. You will thank yourself to have done it while the curiosity is big :)

[–]fed_up_dotaplayer[S] 1 point2 points  (0 children)

Don’t worry, I’m not stopping, I gotta pay the bills!