I am trying to make a program which allows you to enter names and ages and then print
s those values.
I have this code:
print("This is a program to create and edit lists of a maximum of 10 people ")
n1 = input("Enter the name of the first person here: ")
a1 = int(input("Enter the age here: "))
n2 = input("Enter the name of the second person here: ")
a2 = int(input("Enter the age here: "))
n3 = input("Enter the name of the third person here: ")
a3 = int(input("Enter the age here: "))
n4 = input("Enter the name of the fourth person here: ")
a4 = int(input("Enter the age here: "))
n5 = input("Enter the name of the fifth person here: ")
a5 = int(input("Enter the age here: "))
print("Forming your list: ")
p1 = (n1 , " your age is ", a1 + "years old")
p2 = (n2 , " your age is ", a2 + "years old")
p3 = (n3 , " your age is ", a3 + "years old")
p4 = (n4 , " your age is ", a4 + "years old")
p5 = (n5 , " your age is ", a5 + "years old")
print(p1,p2,p3,p4,p5)
ans = input("Would you like to keep adding people? ")
if ans == "yes" :
n6 = input("Enter the name of the sixth person here: ")
a6 = int(input("Enter the age here: "))
n7 = input("Enter the name of the seventh person here: ")
a7 = int(input("Enter the age here: "))
n8 = input("Enter the name of the eighth person here: ")
a8 = int(input("Enter the age here: "))
n9 = input("Enter the name of the ninth person here: ")
a9 = int(input("Enter the age here: "))
n10= input("Enter the name of the tenth person here: ")
a10: int= int(input("Enter the age here: "))
print("Forming your list: ")
p1 = (n1 , " your age is " , a1 + "year s old")
p2 = (n2 , " your age is " , a2 + "years old")
p3 = (n3 , " your age is " , a3 + "years old")
p4 = (n4 , " your age is " , a4 + "years old")
p5 = (n5 , " your age is " , a5 + "years old")
p6 = (n6 , " your age is " , a6 + "years old")
p7 = (n7 , " your age is " , a7 + "years old")
p8 = (n8 , " your age is " , a8 + "years old")
p9 = (n9 , " your age is " , a9 + "years old")
p10= (n10 , " your age is " , a10 + "years old")
print(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10)
if ans == "no" :
print("Thank you for using this service and hope you enjoyed :) ")
I get an error message that says:
File "C:\Users\user1\Documents\Code\Python\HelloWorld\List.py", line 15, in <module>
p1 = (n1 , " your age is ", a1 + "years old")
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Why? What is wrong with the code, and how can I fix it?