更新:所以在采取了一些建议之后,我改变了返回值的方式。编辑如下所示。但是,该程序现在告诉我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