2

I'm trying to convert how many years old you are into days:

print "age into days converter"
name = raw_input("What is your name: ")
age = raw_input("How old are you: ")
days_in_years = 365
age_in_days = age * days_in_years
print "You are %s days old" %age_in_days

However, it prints your age 365 times instead of multiplying it. I tried using input, int(, and trying to convert it to a float value but it still wasn't working.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
charly9011
  • 21
  • 1

2 Answers2

2

You need to replace age_in_days = age * days_in_years with age_in_days = int(age) * days_in_years so that age_in_days is a number and not a string.

Ali Camilletti
  • 116
  • 1
  • 3
  • 11
1

raw_input will return a string which you multiply by an int resulting in string repetition, not int multiplication.

Wrap it in an int call to get the result you need

age = int(raw_input("How old are you: "))
Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253