2016-12-17 9 views
0

更新:いくつかのアドバイスを取った後、値の返り方を変更しました。編集内容は以下に反映されています。しかし、プログラムは今私が適切に今戻しているにもかかわらず、displayRent()関数が 'deposit'値を欠いていると私に伝えています。何か案は?戻り値のエラー

私は私のプログラミングの最後のためにこのプログラムを書いています。それはアパートのタイプとそのような(値1~3,4を終了するために)とその家具付きまたは家具なしの選択に基づいてユーザーの入力が必要です。これらの値を使用して、名前、預金および家賃を検索します。しかし、何らかの理由で、私の値がチェーン内の次の関数に必要なmain()関数に返されていません。

サイドノート:このコードの記述方法は、私の教授の指示通りです。 このプログラムも終了していません。しかし、コードのこれらのビットは私に進行を妨げている問題を与えています。

すべてのご協力ありがとうございます。

################################################## 
# This program displays possible living spaces, # 
# and gives total prices upon certain options of # 
# a said space is chosen.      # 
################################################## 

############################### 
# Matthew Bobrowski   # 
# CSC122-07 Final    # 
# December 17th, 2016   # 
############################### 

print("""Matthew Bobrowski 
CSC 122-07 Final Program 
December 18th, 2016, 11:59pm""") 

def main(): 

    print("Please choose one of the options listed. (1-4)") 
    print(""" 
    1. Studio 
    2. One-Bedroom 
    3. Two-Bedroom 
    4. Exit 
    """) 
    choiceInput, furnishedInput = getType() 
    rent, deposit = determineRent(choiceInput, furnishedInput) 
    displayRent(choiceInput, rent, deposit) 

def getType(): 
    choiceInput = input("Choice: ") 
    furnishedInput = input("Furnished? (Y/N): ") 
    if choiceInput != 1 or choiceInput != 2 or choiceInput != 3 or choiceInput != 4: 
     print("Invalid entry. Please try again.") 
     choiceInput = input("Choice: ") 
    if furnishedInput != 'Y' or furnishedInput != 'y' or furnishedInput != 'N' or furnishedInput != 'n': 
     print("Invalid entry. Please try again.") 
     furnishedInput = input("Furnished? (Y/N): ") 
    return choiceInput, furnishedInput 

def determineRent(choiceInput, furnishedInput): 
    rent = 0 
    deposit = 0 

    if choiceInput == 1: 
     if furnishedInput == 'Y' or furnishedInput == 'y': 
      rent = 750 
      deposit = 400 
     elif furnishedInput == 'N' or furnishedInput == 'n': 
      rent = 600 
      deposit = 400 
    elif choiceInput == 2: 
     if furnishedInput == 'Y' or furnishedInput == 'y': 
      rent = 900 
      deposit = 500 
     elif furnishedInput == 'N' or furnishedInput == 'n': 
      rent = 750 
      deposit = 500 
    elif choiceInput == 3: 
     if furnishedInput == 'Y' or furnishedInput == 'y': 
      rent = 1025 
      deposit = 600 
     elif furnishedInput == 'N' or furnishedInput == 'n': 
      rent = 925 
      deposit = 600 
    elif choiceInput == 4: 
     quit 
    return rent, deposit 

def displayRent(choiceInput, furnishedInput, rent, deposit): 
    if choiceInput == 1: 
     if furnishedInput == 'y' or furnishedInput == 'Y': 
      print(""" 
      TYPE: STUDIO - FURNISHED 
      DEPOSIT: $""" + str(deposit) + """ 
      RENT: $""" + str(rent)) 
     else: 
      print(""" 
      TYPE: STUDIO - UNFURNISHED 
      DEPOSIT: $""" + str(deposit) + """ 
      RENT: $""" + str(rent)) 
    return 


main() 

答えて

0

getType()は値を返しますか?だから、それらを捕まえる。

choiceInput, furnishedInput = getType() # Get the values 
determineRent(choiceInput, furnishedInput) # Same issue here... 

第二の問題:文字列を返しますinput()。あなたはそれを

choiceInput = int(input("Choice: ")) 

チップをキャストする必要があります:あなたの文は機能を持っていて、何かを返す場合は、必要に、値

if furnishedInput.lower() == 'y': 
+0

私はこれをやってみると、入力を2回ずつ呼び出して失敗しました。 – Matt

+0

おそらくあなたは文字列とintsを比較しています –

+0

実際には、心配しないでください。以前の繰り返しが間違っていました。それは今通過する。どうもありがとうございます! – Matt

0

オーケーを小文字にして簡略化することができた場合返された結果を保存します。

オプションを選択しない場合は、比較する場合はを使用してください:

if choiceInput != 1 and choiceInput != 2 and choiceInput != 3 and choiceInput != 4: 

または少しのpythonのように:

if choiceInput not in (1,2,3,4): 

また、ループを使用することを検討し、もし条件条件はユーザーのみが2障害のあるに入ったらどう、1つの障害のある入力をキャッチしますエントリ?

+0

私のプログラムが無効な入力をチェックしているという事実を追加するのを忘れましたが、デバッグ中に削除しました。私は、受け入れられたものが与えられるまで、入力ごとに誤入力を再ロードしました。 :) – Matt