Convert year to seconds in Python
Question:
I’m stuck on an assignment which needs me to convert an input of years and print the result in seconds. The error message I get when I run the function is:
'*TypeError: not all arguments converted during string formatting*'
I can’t really get my head around what’s wrong…
def ageInSeconds():
"""
Reads the age and converts to seconds.
"""
ageYears = int(input("Tell me your age, please: "))
seconds = ageYears * (365*24*60*60)
print("nBatman says you age in seconds is: " % seconds)
Answers:
You are missing a %d
inside the string.
print("nBatman says you age in seconds is: %d" % seconds)
^
Else you can do
print("nBatman says you age in seconds is:",seconds) # Inbuilt feature of the print function
Years = int(input("Tell me the year, please: "))
answer = Years * (365*24*60*60)
print("There are", answer, "seconds in a year/years")
I’m stuck on an assignment which needs me to convert an input of years and print the result in seconds. The error message I get when I run the function is:
'*TypeError: not all arguments converted during string formatting*'
I can’t really get my head around what’s wrong…
def ageInSeconds():
"""
Reads the age and converts to seconds.
"""
ageYears = int(input("Tell me your age, please: "))
seconds = ageYears * (365*24*60*60)
print("nBatman says you age in seconds is: " % seconds)
You are missing a %d
inside the string.
print("nBatman says you age in seconds is: %d" % seconds)
^
Else you can do
print("nBatman says you age in seconds is:",seconds) # Inbuilt feature of the print function
Years = int(input("Tell me the year, please: "))
answer = Years * (365*24*60*60)
print("There are", answer, "seconds in a year/years")