Thomas Bengtsson
Thomas Bengtsson

Reputation: 399

Convert year to seconds in Python

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)

Upvotes: 2

Views: 5633

Answers (2)

Sivario Buchanan
Sivario Buchanan

Reputation: 1

Years = int(input("Tell me the year, please: "))

answer = Years * (365*24*60*60)

print("There are", answer, "seconds in a year/years")

Upvotes: -2

Bhargav Rao
Bhargav Rao

Reputation: 52071

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

Upvotes: 4

Related Questions