[英]how do i turn an input into a variable so i can add or use in equations in python
if I have a code like this?如果我有这样的代码?
num1= input (" number goes here")
num2= input ("number goes here")
how can I make a simple equation work such as.我怎样才能使一个简单的方程式起作用,例如。
num3=num2+num1
print ("num3")
and when I do that it outputs当我这样做时,它会输出
num2num3
I have tried things such as我尝试过诸如
int=(num1)
You need to convert num1 and num2 into int type because input gives you a str type.您需要将 num1 和 num2 转换为 int 类型,因为 input 为您提供了 str 类型。
num1 = int(input(" number goes here"))
num2 = int(input("number goes here"))
num3 = num1 + num2
print(num3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.