更新:所以在採取了一些建議之後,我改變了返回值的方式。編輯如下所示。但是,該程序現在告訴我displayRent()函數缺少'存款'值,即使我現在正確地返回它。有任何想法嗎?返回值的錯誤
所以我正在爲我的編程最終編寫這個程序。它根據公寓的類型和用戶輸入(值1-3,4退出)以及他們選擇裝修還是未裝修。通過這些值,它可以找到名稱,存款和租金。但是,出於某種原因,我的值沒有被返回到main()函數中,鏈接中的下一個函數需要它們。
Sidenotes:這段代碼的寫法與我的教授一致。 該程序還未完成。但是,這些代碼給我的問題阻礙了我的進步。
所有幫助表示讚賞!
##################################################
# 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()
當我試圖做到這一點時,它每次回想兩次輸入,然後失敗。 – Matt
大概你是比較字符串和整數 –
其實,沒關係。之前的迭代有些不正確;它現在通過。非常感謝! – Matt