I don\'t know what\'s wrong with my source code...The programming language is py
ID: 3772720 • Letter: I
Question
I don't know what's wrong with my source code...The programming language is python.
The instructions are like this:
There is a table
1. main – This function should be designed to call the three (3) functions below (2- 4).
2. getType – This function will get the type of apartment the user wishes to rent. The possible types are 1 – Studio, 2 – One-Bedroom, 3 – Two Bedroom and 4 to Exit the Program. This function should accept no arguments/parameters and return two variables (kind and furnished) back to the main part of the program that called it. The variable kind should store the type of apartment selected and the variable furnished should store the value “Y” (or “y”) or “N” (or “n”) to indicate if the apartment should be furnished or unfurnished.
3. determineRent – This function should be designed to accept the kind and furnished variables (as parameters) and use this information to determine the amount of the rent and deposit and return these two values (rent and deposit) back to the main part of the program that called it.
4. displayRent – This function should be designed to display the apartment description, required deposit, and monthly rent based on the choices entered by the user. See the sample output screen captures below. The function should be setup to accept four (4) arguments/parameters (kind, furnished, rent, deposit).
Here is my source code and it keeps saying "name 'kind' is not defined."
def main():
print("Apartment Rental Program")
print("Studio ---------> 1")
print("One Bedroom ----> 2")
print("Two Bedroom ----> 3")
print("Exit Program ---> 4")
getType()
determineRent(kind,furnished)
displayRent(rent,deposit)
def getType():
kind = int(input("Enter the type of apartment you wish to rent (1-3 or 4 to Exit Program) :"))
if kind == 1 or kind == 2 or kind == 3:
furnished = input("Do you want the apartment furnished (Y/N)?")
elif kind == 4:
print("Thanks for inquiring about out apartments for rent!")
else:
print("Invalid apartment type...must be 1-4!")
return kind
return furnished
def determineRent(kind, furnished):
if kind == 1:
if furnished == 'Y' or furnished == 'y':
rent = '750'
deposit = '400'
elif furnished == 'N' or furnished == 'n':
rent = '600'
deposit = '400'
elif kind == 2:
if furnished == 'Y' or furnished == 'y':
rent = '900'
deposit = '500'
elif furnished == 'N' or furnished == 'n':
rent = '750'
deposit = '500'
elif kind == 3:
if furnished == 'Y' or furnished == 'y':
rent = '1025'
deposit = '600'
elif furnished == 'N' or furnished == 'n':
rent = '925'
deposit = '600'
return rent,deposit
def displayRent(kind,furnished,rent,deposit):
print("Type: ", kind)
print("Furnished: ", furnished)
print("Deposit: $", deposit)
print("Rent: $", rent)
main()
type deposit unfurnished furnished 1 400 600 750 2 500 750 900 3 625 900 1025Explanation / Answer
Answer:
Issue with your code was
1. getType method is returning two values but in differnt lines.So only 1 was getting considered. and if a function return something you have to cath it and store it in some variable.
2. Input and raw_input method.
input function in Python 2.7, evaluates whatever your enter, as a Python expression. If you simply want to read strings, then use raw_input function in Python 2.7, which will not evaluate the read strings.
If you are using Python 3.x, raw_input has been renamed to input.
Corect Program:
def main():
print("Apartment Rental Program")
print("Studio ---------> 1")
print("One Bedroom ----> 2")
print("Two Bedroom ----> 3")
print("Exit Program ---> 4")
kind , furnished = getType()
rent , deposit = determineRent(kind,furnished)
displayRent(kind,furnished,rent,deposit)
def getType():
kind = int(input("Enter the type of apartment you wish to rent (1-3 or 4 to Exit Program) :"))
if kind == 1 or kind == 2 or kind == 3:
furnished = raw_input("Do you want the apartment furnished (Y/N)?")
print furnished
elif kind == 4:
print("Thanks for inquiring about out apartments for rent!")
else:
print("Invalid apartment type...must be 1-4!")
return (kind,furnished)
def determineRent(kind, furnished):
if kind == 1:
if furnished == 'Y' or furnished == 'y':
rent = '750'
deposit = '400'
elif furnished == 'N' or furnished == 'n':
rent = '600'
deposit = '400'
elif kind == 2:
print furnished
if furnished == 'Y' or furnished == 'y':
rent = '900'
deposit = '500'
elif furnished == 'N' or furnished == 'n':
rent = '750'
deposit = '500'
elif kind == 3:
if furnished == 'Y' or furnished == 'y':
rent = '1025'
deposit = '600'
elif furnished == 'N' or furnished == 'n':
rent = '925'
deposit = '600'
return rent,deposit
def displayRent(kind,furnished,rent,deposit):
print("Type: ", kind)
print("Furnished: ", furnished)
print("Deposit: $", deposit)
print("Rent: $", rent)
main()
Output:
Apartment Rental Program
Studio ---------> 1
One Bedroom ----> 2
Two Bedroom ----> 3
Exit Program ---> 4
Enter the type of apartment you wish to rent (1-3 or 4 to Exit Program) :Do you want the apartment furnished (Y/N)?N
N
('Type: ', 2)
('Furnished: ', 'N')
('Deposit: $', '500')
('Rent: $', '750')
Thanks
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.