1

[Update] I see that roomidea() is called in two different locations:

def price(): sBedsize, sRoomview, sVehicle, iRoomnum, iNights = roomidea() and sBedsize, sRoomview, sVehicle, iRoomnum, iNights = roomidea()

But the problem is that whenever I remove the one location under def price(): it causes an error saying iNights is not defined which it is defined but only under the first def.

My current problem is this, whenever I run my program in pycharm it prints the input twice, now I have a few ideas of why this may happen but whenever I try to solve these ideas it either doesn't work or it causes even more errors or problems. Now I have my input inside a function and I call back to that function later, now I don't know if I call back to it twice because I have the callback also inside my second def which is the price one but I would appreciate if you looked and told me.

import time
def roomidea():
    sBedsize = input("For your room do you want a queen-size bed or a king-size bed? Type Queen for queen-size or King for king-size:\t")
    sRoomview = input("For your room do you want the standard view or the atrium view? Type Standard for standard-view or Atrium for atrium-view:\t")
    sVehicle = input("Will you be parking at our hotel? Type Yes if you are, or No if you are not:\t")
    iRoomnum = int(input("Please enter the amount of rooms you wish to check out:\t"))
    iNights = int(input("Please enter the amount of nights you wish to stay:\t"))
    return sBedsize, sRoomview, sVehicle, iRoomnum, iNights

def price():
    sBedsize, sRoomview, sVehicle, iRoomnum, iNights = roomidea()
    dPrice1 = iNights * 280
    dPrice2 = iNights * 320
    dPrice3 = iNights * 295.50
    dPrice4 = iNights * 335.50
    dPrice5 = iNights * 15.75
    dResortfee1 = iNights * 20
    dResortfee2 = iRoomnum * 20
    dTotalqs = dPrice1 + dPrice5 + dResortfee1 + dResortfee2
    dTotalqa = dPrice2 + dPrice5 + dResortfee1 + dResortfee2
    dTotalqsv = dPrice1 + dResortfee1 + dResortfee2
    dTotalqav = dPrice2 + dResortfee1 + dResortfee2
    dTotalks = dPrice3 + dPrice5 + dResortfee1 + dResortfee2
    dTotalka = dPrice4 + dPrice5 + dResortfee1 + dResortfee2
    dTotalksv = dPrice3 + dResortfee1 + dResortfee2
    dTotalkav = dPrice4 + dResortfee1 + dResortfee2
    dTaxqs = dTotalqs * 0.15
    dTaxqa = dTotalqa * 0.15
    dTaxqsv = dTotalqsv * 0.15
    dTaxqav = dTotalqav * 0.15
    dTaxks = dTotalks * 0.15
    dTaxka = dTotalka * 0.15
    dTaxksv = dTotalksv * 0.15
    dTaxkav = dTotalkav * 0.15
    dOverallqs = dTotalqs + dTaxqs
    dOverallqa = dTotalqa + dTaxqs
    dOverallqsv = dTotalqsv + dTaxqs
    dOverallqav = dTotalqav + dTaxqs
    dOverallks = dTotalks + dTaxqs
    dOverallka = dTotalka + dTaxqs
    dOverallksv = dTotalksv + dTaxqs
    dOverallkav = dTotalkav + dTaxqs
    return dPrice1, dPrice2, dPrice3, dPrice4, dPrice5, dResortfee1, dResortfee2, dTotalqs, dTotalqa, dTotalqsv, dTotalqav, dTotalks, dTotalka, dTotalksv, dTotalkav, dTaxqs, dTaxqa, dTaxqsv, dTaxqav, dTaxks, dTaxka, dTaxksv, dTaxkav, dOverallqs, dOverallqa, dOverallqsv, dOverallqav, dOverallks, dOverallka, dOverallksv, dOverallkav

dPrice1, dPrice2, dPrice3, dPrice4, dPrice5, dResortfee1, dResortfee2, dTotalqs, dTotalqa, dTotalqsv, dTotalqav, dTotalks, dTotalka, dTotalksv, dTotalkav, dTaxqs, dTaxqa, dTaxqsv, dTaxqav, dTaxks, dTaxka, dTaxksv, dTaxkav, dOverallqs, dOverallqa, dOverallqsv, dOverallqav, dOverallks, dOverallka, dOverallksv, dOverallkav = price()
sBedsize, sRoomview, sVehicle, iRoomnum, iNights = roomidea()

if  sBedsize == "Queen" and sRoomview == "Standard" and sVehicle == "Yes":
    print("The price for a Queen-Size bed with the Standard view and you are parking a vehicle, this comes to the total of $%.2f" % dTotalqs + " If this is how you want your room, type Yes, if you want to pick another option, type No.")
elif sBedsize == "Queen" and sRoomview == "Atrium" and sVehicle == "Yes":
    print("The price of Queen-Size bed with the Atrium view and you are parking a vehicle, this comes to the total of $%.2f" % dTotalqa + " If this is how you want your room, type Yes, if you want to pick another option, type No.")
elif sBedsize == "Queen" and sRoomview == "Standard" and sVehicle == "No":
    print("The price for a Queen-Size bed with the Standard view and you are not parking a vehicle, this comes to the total of $%.2f" % dTotalqsv + " If this is how you want your room, type Yes, if you want to pick another option, type No.")
elif sBedsize == "Queen" and sRoomview == "Atrium" and sVehicle == "No":
    print("The price for a Queen-Size bed with the Atrium view and you are not parking a vehicle, this comes to the total of $%.2f" % dTotalqav + " If this is how you want your room, type Yes, if you want to pick another option, type No.")
elif sBedsize == "King" and sRoomview == "Standard" and sVehicle == "Yes":
    print("The price for a King-Size bed with the Standard view and you are parking a vehicle, this comes to the total of $%.2f" % dTotalks + " If this is how you want your room, type Yes, if you want to pick another option, type No.")
elif sBedsize == "King" and sRoomview == "Atrium" and sVehicle == "Yes":
    print("The price for a King-Size bed with the Atrium view and you are parking a vehicle, this comes to the total of $%.2f" % dTotalka + " If this is how you want your room, type Yes, if you want to pick another option, type No.")
elif sBedsize == "King" and sRoomview == "Standard" and sVehicle == "No":
    print("The price for a King-Size bed with the Standard view and you are not parking a vehicle, this comes to the total of $%.2f" % dTotalksv + " If this is how you want your room, type Yes, if you want to pick another option, type No.")
elif sBedsize == "King" and sRoomview == "Atrium" and sVehicle == "No":
    print("The price for a King-Size bed with the Standard view and you are not parking a vehicle, this comes to the total of $%.2f" % dTotalkav + " If this is how you want your room, type Yes, if you want to pick another option, type No.")
else:
    print("You did not enter the information correctly")
time.sleep(5)
feedback = input("Would you like to change your room choices? Type Yes or No for the options").upper()
if feedback == "YES":
    print("Thank you for picking a room with us, I hope you enjoy your room and we are hoping to see you back again!")
elif feedback == "NO":
    print("We are sorry that the room you picked isn't how you wanted it, please retype how you want your room, if you want to leave just type quit")
    time.sleep(5)
  • 1
    You are calling `roomidea()` in two places – Michael Butscher Oct 18 '18 at 23:00
  • Can you explain, I use it one time here : def price(): sBedsize, sRoomview, sVehicle, iRoomnum, iNights = roomidea() Then I use it again here: sBedsize, sRoomview, sVehicle, iRoomnum, iNights = roomidea() But if I don't include it inside the def price function it says iNights is not defined – JosephCline101 Oct 18 '18 at 23:01
  • Just search through the code, you will find two calls. – Michael Butscher Oct 18 '18 at 23:02
  • I see it twice, but if i remove it from def price(): sBedsize, sRoomview, sVehicle, iRoomnum, iNights = roomidea() It says "iNights is not defined" – JosephCline101 Oct 18 '18 at 23:03
  • 1
    Call `roomidea` first and give the returned data as parameters in the call to `price(...)` so `price` doesn't have to retrieve the data again. Alternatively, the other way around: `price` calls `roomidea` and additionally returns the data retrieved through the `roomidea` call, so the second call to `roomidea` isn't necessary anymore. – Michael Butscher Oct 18 '18 at 23:07
  • 2
    Completely unrelated, but you should [avoid using Systems Hungarian notation](https://stackoverflow.com/questions/8791533/does-it-make-sense-to-use-hungarian-notation-prefixes-in-interpreted-languages) (in python, especially, but also in other languages). – David Zemens Oct 18 '18 at 23:17

1 Answers1

0

you may need to think about better logic. the issue is, since you are using sBedSize, sRoomview, sVehicle outside of method def price():, it is expected to crash. return them from price()

return sBedsize, sRoomview, sVehicle, iRoomnum, iNights, dPrice1, dPrice2, dPrice3, dPrice4, dPrice5, dResortfee1, dResortfee2, dTotalqs, dTotalqa, dTotalqsv, dTotalqav, dTotalks, dTotalka, dTotalksv, dTotalkav, dTaxqs, dTaxqa, dTaxqsv, dTaxqav, dTaxks, dTaxka, dTaxksv, dTaxkav, dOverallqs, dOverallqa, dOverallqsv, dOverallqav, dOverallks, dOverallka, dOverallksv, dOverallkav

sBedsize, sRoomview, sVehicle, iRoomnum, iNights, dPrice1, dPrice2, dPrice3, dPrice4, dPrice5, dResortfee1, dResortfee2, dTotalqs, dTotalqa, dTotalqsv, dTotalqav, dTotalks, dTotalka, dTotalksv, dTotalkav, dTaxqs, dTaxqa, dTaxqsv, dTaxqav, dTaxks, dTaxka, dTaxksv, dTaxkav, dOverallqs, dOverallqa, dOverallqsv, dOverallqav, dOverallks, dOverallka, dOverallksv, dOverallkav = price()

#sBedsize, sRoomview, sVehicle, iRoomnum, iNights = roomidea()
user3713719
  • 325
  • 3
  • 8