简体   繁体   English

如何将输入转换为变量,以便我可以在 python 中的方程中添加或使用

[英]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.

相关问题 如何获取价格并将其转换为我可以使用的变量 - How do I take the price and turn it into a variable I can use Discord Python:如何保护变量中的用户名/ID,以便我可以使用它来调整他们的角色 - Discord Python: How do i safe a User Name/ID in a variable so i can use it to adjust their roles 如何使用 append 将答案添加到数组以从输入中注册,以便我可以使用输入中的答案登录? - How do I use append to add the answer to an array for registration from input so I can log in using the answer from the input? 如何求解 python 中的 8 个变量和 8 个方程线性系统? - How do I solve 8 variable and 8 equations linear system in python? 如何使用 python 上的牛顿法求解方程组? - How do I use newtons method on python to solve a system of equations? 如何在 sympy 中的方程上使用 -、+、*、/ 等操作? - How do I use operations such as -, +, *, / on equations in sympy? 如何用纯Python编写这些方程式? - How do I write these equations in pure Python? 如何将变量输入用于 python 字典? - How can I use the variable input into a python dictionary? 如何将存储在变量中的Python字符串转换为字节序列? - How do I turn a Python string stored in a variable into a byte sequence? 如何将索引变成变量以便我可以将它用于 tkinter? - How do i make an index into a variable so i can use it for tkinter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM