0
name = input("Please enter your name: ")
age = input("Please enter your age: ")
print ("Hello, " + name + ", you are " + age * 7 + " Years old in Dog years.").

This is my code and this is what I get.

Please enter your name: paris
Please enter your age: 13
Hello, paris, you are 13131313131313 Years old in Dog years.

I want 13 x 7 not 13 7 times. Can someone please help me? thx

2 Answers2

2

In python you can do this str * 7 and as you can see it will repeat it 7 times.

For what you want you want to cast age to int int(age) or cast your input to only accept ints age = int(input("enter age")) Like in the comments say.

For future reference you can test the type of a variable using type(<variable>)

Edit...

name = input("Please enter your name: ")
age = int(input("Please enter your age: "))
print ("Hello, " + name + ", you are " , age * 7 , " Years old in Dog years.")
MooingRawr
  • 4,901
  • 3
  • 24
  • 31
1

Multipling a string with a integer is repeating it multiple times. You have to convert age to a number before doing calculations:

print("Hello, {}, you are {} Years old in Dog years.".format(name, int(age) * 7)
Daniel
  • 42,087
  • 4
  • 55
  • 81