ОБНОВЛЕНИЕ: Итак, после принятия некоторых рекомендаций, я изменил способ возврата значений. Изменения отражены ниже. Тем не менее, программа теперь говорит мне, что функция 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
Возможно, вы сравниваете строки и ints –
Собственно, неважно. Что-то было неправильным предыдущей итерацией; он проходит сейчас. Спасибо огромное! – Matt