更新:いくつかのアドバイスを取った後、値の返り方を変更しました。編集内容は以下に反映されています。しかし、プログラムは今私が適切に今戻しているにもかかわらず、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()
私はこれをやってみると、入力を2回ずつ呼び出して失敗しました。 – Matt
おそらくあなたは文字列とintsを比較しています –
実際には、心配しないでください。以前の繰り返しが間違っていました。それは今通過する。どうもありがとうございます! – Matt