2017-10-02 16 views
-1

私は方程式の計算をしようとしています。xの前に数字があるかどうかを調べるためのチェッカーを持っていますか?それを増やすことができるようにします。 raw_inputに数字があるかどうかを確認するにはどうすればよいですか?方程式計算のために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) 
+0

はplzは、あなたの仕事を表示します。 –

+0

これはあまり残念なことです。 –

+0

raw_input()に数字があるのはどういう意味ですか? 'x = raw_input( 'prompt:')'は、ユーザが入力したテキストが変数xに代入されたことを意味します。 – Holloway

答えて

0

これはのみ、数字のみの入力のための数や文字のないミックスを動作します(ただし、私はそれを可能にするために、これを変更することができます)

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