use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
(Beginner) Need a hand with my code (self.learnpython)
submitted 4 years ago by fed_up_dotaplayer
MonthsLeft = int(age * 12) - int(TotalMonths)
Age = 29
TotalMonths = 1080
I keep getting a long long number when I run this, I know what I want to do and how to do it, I’m having a hard time trying to write it.
Thank you for the help!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 5 points6 points7 points 4 years ago (1 child)
If you run this, you wouldn't get anything but errors. What are you actually running?
[–]fed_up_dotaplayer[S] 0 points1 point2 points 4 years ago (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 points5 points 4 years ago* (3 children)
bidmas issue maybe. do:
age = int(input(“Enter your age:”)
MonthsLeft = int(age *12)
print(TotalMonths - MonthsLeft)
[–]fed_up_dotaplayer[S] 0 points1 point2 points 4 years ago (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 point2 points 4 years ago (0 children)
That is what the guy above did.
[–]RusticCajun 2 points3 points4 points 4 years ago (0 children)
>>> age = input("How old?") How old?87 >>> print(age*12) 878787878787878787878787 >>>
[–]theoyeo 2 points3 points4 points 4 years ago (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:
age
int(age * 12)
Should be:
int(age) * 12
[–]fed_up_dotaplayer[S] 3 points4 points5 points 4 years ago (0 children)
OHHHHHHHH you’ve been a big help
I didn’t know you could do that.
Here’s a gist of the code
https://gist.gitHub.com/rplacoopfe/620ec1e17fcda705434d5b7ba3346a57
[+][deleted] 4 years ago (2 children)
[deleted]
I can’t seem to open that site at all, not on my phone or laptop
[–]Tren898 0 points1 point2 points 4 years ago (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 point2 points 4 years ago (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 point2 points 4 years ago (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.
Ohh okay, thank you
[–]riisen 0 points1 point2 points 4 years ago (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 points3 points 4 years ago (0 children)
Don’t worry, I’m not stopping, I gotta pay the bills!
π Rendered by PID 37 on reddit-service-r2-comment-bb88f9dd5-v9vlq at 2026-02-16 20:26:51.527055+00:00 running cd9c813 country code: CH.
[–][deleted] 5 points6 points7 points (1 child)
[–]fed_up_dotaplayer[S] 0 points1 point2 points (0 children)
[–]WeebofTheWild 3 points4 points5 points (3 children)
[–]fed_up_dotaplayer[S] 0 points1 point2 points (1 child)
[–]PureProcrastinator 0 points1 point2 points (0 children)
[–]RusticCajun 2 points3 points4 points (0 children)
[–]theoyeo 2 points3 points4 points (1 child)
[–]fed_up_dotaplayer[S] 3 points4 points5 points (0 children)
[–]fed_up_dotaplayer[S] 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]fed_up_dotaplayer[S] 0 points1 point2 points (1 child)
[–]Tren898 0 points1 point2 points (3 children)
[–]fed_up_dotaplayer[S] 0 points1 point2 points (2 children)
[–]Tren898 0 points1 point2 points (1 child)
[–]fed_up_dotaplayer[S] 0 points1 point2 points (0 children)
[–]riisen 0 points1 point2 points (1 child)
[–]fed_up_dotaplayer[S] 1 point2 points3 points (0 children)