2016-07-25 13 views
0

私はモジュールを使いこなしていますが、モジュールを乗算しながらユーザー入力を検証しようとしています。私が邪魔していないサークルの領域が、私は一度これを把握します。長方形の領域は私が問題があるものです。これは初めて動作しますが、ユーザーが何か間違った情報を入力した後、再度入力すると、none型として表示されます。あなたがしたときにエラーの後Rectangle_WidthまたはRectangle_Heightを再呼び出し、あなたはドン」 -TypeError-サポートされていないオペランドタイプ

code

def Area_Of_A_Rectangle(): 
    print("To Find the Area of a Rectangle we need two things") 
    print("The Area of a Rectangle: ",Rectangle_Height() * Rectangle_Width()) 


##!--------------------Validation Modules------------------!## 


#-----Rectangle Height Input------------------------------------------------  
def Rectangle_Height(): 
    try: 
    Rec_Height = float(input("What is the Height of your Rectangle: ")) 
    except ValueError: 
    print("Please Try Again!") 
    Rectangle_Height() 
    else: 
    return Rec_Height 

#-----Rectangle Width------------------------------------------------------- 
def Rectangle_Width(): 
    try: 
    Rec_Width = float(input("What is the Width of your Rectangle: ")) 
    except ValueError: 
    print("Please Try Again!") 
    Rectangle_Width() 
    else: 
    return Rec_Width 


Area_Of_A_Rectangle() 
+0

テキストとしてではなく、イメージとしてのコードを投稿してください。 – Renzo

+0

よろしくお願いします... – Hoyt

答えて

0

非常にシンプル:次のように

エラー

TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

コードですその結果を返します。

すなわち:正直なところ

Rectange_Width() 

return Rectangle_Width() 

、これは例外と再帰呼び出しを使用していない、ループ内で行われるべきです。例えば

while True: 
    Rec_Width = None 
    try: 
     Rec_Width = float(input("What is the Width of your Rectangle: ")) 
    except ValueError: 
     print("Please try again!") 
     continue 
    else: 
     return Rec_Width 
関連する問題