[英]How do you look and see if there is a number in a raw_input for an equation calculator
我正在尝试制作一个方程计算器 我正在尝试为方程设置一个检查器,以查看 x 或 y 之前是否有一个数字,以便它可以乘以它。 我将如何检查 raw_input 中是否有任何数字?
def x_pluse_y(total):
x = raw_input('what is your x? ' )
y = raw_input('what is your y? ' )
if x == 'x':
x = 0
if y == 'y':
y = 0
float(x) + float(y) == float(total)
step1 = float(total) - float(y)
x = step1
step2 = int(total) - int(x)
y = step2
print 'Your x is ' + str(x)
print 'Your y is ' + str(y)
def x_minus_y(total):
x = raw_input('what is your x? ' )
y = raw_input('what is your y? ' )
if x == 'x':
x = float(0)
if y == 'y':
y = float(0)
if x > 0:
x == x
elif y > 0:
y == y
if float(x) > 0:
y = float(total) - float(x)
if float(y) > 0 :
x = float(total) - float(y)
print 'Your x is ' + str(x)
print 'Your y is ' + str(y)
def multi_x(equation):
x = raw_input('what is your x? ' )
y = raw_input('what is your y? ' )
if x == 'x':
x = float(0)
if y == 'y':
y = float(0)
if x > 0:
x == x
elif y > 0:
y == y
if float(x) > 0:
y = float(equation) - float(x)
if float(y) > 0 :
x = float(equation) - float(y)
print 'Your x is ' + str(x)
print 'Your y is ' + str(y)
这仅适用于仅输入数字,而不适用于数字或字母的混合(但我可以修改它以允许)
def CheckStrIfVar(var):
try:
#If it is not a number this will raise an error, hence why I'm using exceptions
test = int(var)
return True
except:
#Will run if it cannot convert it to a var
return False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.