Python Forum
Calculation error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Calculation error (/thread-13040.html)



Calculation error - RustyShacklevert - Sep-25-2018

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



RE: Calculation error - Larz60+ - Sep-25-2018

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
>>>



RE: Calculation error - RustyShacklevert - Sep-25-2018

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"?


RE: Calculation error - Larz60+ - Sep-25-2018

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


RE: Calculation error - RustyShacklevert - Sep-25-2018

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.