Python – Can't convert int to str implicity in this specific code
Question:
I had a GCSE question, where Python is asking me to input three numbers in a function and print the largest one.
My problem is, that it shows the error Can't convert int to str implicity
.
inputed_1 = int(input("Give me a number: "))
inputed_2 = int(input("Give me another number: "))
inputed_3 = int(input("Give me another number: "))
def largest(num1, num2, num3):
if num1 > num2 and num1 > num3:
print("Your first number was the largest: " + num1)
elif num2 > num1 and num2 > num3:
print("Your second number was the largest: " + num2)
elif num3 > num1 and num3 > num2:
print("Your third number was the largest: " + num3)
largest(inputed_1, inputed_2, inputed_3)
Answers:
Try converting your integers to strings before concatenating them:
print("Your first number was the largest: " + str(num1))
I had a GCSE question, where Python is asking me to input three numbers in a function and print the largest one.
My problem is, that it shows the error Can't convert int to str implicity
.
inputed_1 = int(input("Give me a number: "))
inputed_2 = int(input("Give me another number: "))
inputed_3 = int(input("Give me another number: "))
def largest(num1, num2, num3):
if num1 > num2 and num1 > num3:
print("Your first number was the largest: " + num1)
elif num2 > num1 and num2 > num3:
print("Your second number was the largest: " + num2)
elif num3 > num1 and num3 > num2:
print("Your third number was the largest: " + num3)
largest(inputed_1, inputed_2, inputed_3)
Try converting your integers to strings before concatenating them:
print("Your first number was the largest: " + str(num1))