1、请务必从 input 函数返回数字,必须使用 int 或 float 将字符串转换为数值。 在此,我们使用的是 int,但是任意一种转换均可。
2、此外,若要输出字符串中的数字,必须使用 str 函数将这些数字转换为字符串,以便连接结果。
# Read the first number
x = int(input('Enter the first number: '))
# Get the second number
y = int(input('Enter the second number: '))
# Add them together
result = x + y
# Display the results
print(str(x) + " + " + str(y) + " = " + str(result))下一节© 2021 Python学习网 苏ICP备16018502号-40