Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculation error
#1
I'm new to programming and i'm trying to make a simple calculator that calculates how many days, minutes and seconds someone has been alive. Everytime I run it and give the age "9" for example, it only prints out a bunch of 9s.

print("Answer the questions to find out how long you have been living in this world")
name = input('What is your name? ')
print('What is your age ',(name),'?')
age=input('age: ')
days=age*365
minutes=age*525600
seconds=age*31536000
print(name,'Has been alive for:', days,'days',minutes,'minutes',seconds,'seconds')
Reply
#2
print("Answer the questions to find out how long you have been living in this world")
name = input('What is your name? ')
print('What is your age ',(name),'?')
age=input('age: ')
entire:
>>> name = input('What is your name? ')
What is your name? Figaro
>>> age = int(input('What is your age {} ? '.format(name)))
What is your age Figaro ? 24
>>> days = age * 365
>>> minutes = days * 24 * 60
>>> seconds = minutes * 60
>>> print('{} Has been alive for {} days, {} minutes, seconds, {}'.format(name, days, minutes, seconds))
Figaro Has been alive for 8760 days, 12614400 minutes, seconds, 756864000
>>>
Reply
#3
Thank you so much, I just started learning programming today (i'm sure you could tell lol). I did'nt even know a .format syntax existed. Why did you do "minutes = days * 24 * 60"?
Reply
#4
It gets better, If you are using python 3.6 or better, there's f-string
print statement would be:
print(f'{name} Has been alive for {days} days, {minutes} minutes, seconds, {seconds}')
minutes = 24 (hours in a day) * 60 (minutes in an hour) thus:
minutes = days * 24 * 60
Reply
#5
Yea, I realized that after asking the question. I'm running Linux mint so i'm currently on 2.7, but i'll take your advice and upgrade asap.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python Calculation error: 39.8-0.1=39.699999999999996 wei 2 2,098 Jun-10-2019, 10:22 AM
Last Post: wei
  Calculation Inside Dictionary Error prophet11 3 2,618 Apr-22-2019, 05:23 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020