0

Write a program that calculates your dogs age in “dog” years. Here is an example interaction between your program and the user:

How old is your dog: 3

Your dog is 21 in “dog” years.

my code:

age = input("How old is your dog: ")

dogage = age*7

print("Your dog is ",dogage," in dog years")
Guy
  • 46,488
  • 10
  • 44
  • 88
Johnny F.
  • 7
  • 3
  • See https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers – LeoE Jan 08 '20 at 10:17
  • 4
    Does this answer your question? [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – LeoE Jan 08 '20 at 10:18

1 Answers1

1
age = input("How old is your dog: ")

dogage = int(age)*7

print("Your dog is ",dogage," in dog years")
Mayowa Ayodele
  • 549
  • 2
  • 11
  • Yep, what you get from the input function will be a string, so you're basically saying dogage="3"*7, which will just return a string made up of 7 copies of the string "3" joined together ("3333333"). The int(age) part tells python to convert the string "3" in to the integer 3, which you can then do mathematical operations on. – Ben Jan 08 '20 at 11:14