Python - 无法在此特定代码中将 int 隐式转换为 str
Python - Can't convert int to str implicity in this specific code
我有一个 GCSE 问题,其中 Python 要求我在一个函数中输入三个数字并打印最大的一个。
我的问题是,它显示错误 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)
在连接它们之前尝试将整数转换为字符串:
print("Your first number was the largest: " + str(num1))
我有一个 GCSE 问题,其中 Python 要求我在一个函数中输入三个数字并打印最大的一个。
我的问题是,它显示错误 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)
在连接它们之前尝试将整数转换为字符串:
print("Your first number was the largest: " + str(num1))