gpt4 book ai didi

Python,错误/Bug,打印输出两次,def/函数

转载 作者:太空宇宙 更新时间:2023-11-03 21:40:42 25 4
gpt4 key购买 nike

[更新]我看到 roomidea() 在两个不同的位置被调用:

定义价格(): sBedsize、sRoomview、sVehicle、iRoomnum、iNights = roomidea()和sBedsize、sRoomview、sVehicle、iRoomnum、iNights = roomidea()

但问题是,每当我删除 def Price(): 下的一个位置时,都会导致错误,提示 iNights 未定义,但它已定义,但仅在第一个 def 下定义。

我当前的问题是这样的,每当我在 pycharm 中运行程序时,它都会打印输入两次,现在我有一些关于为什么会发生这种情况的想法,但每当我尝试解决这些想法时,它要么不起作用,要么导致甚至更多的错误或问题。现在我在一个函数内有我的输入,稍后我会回调该函数,现在我不知道是否会回调它两次,因为我在第二个 def 中也有回调,这是价格之一,但如果你看了并告诉我。

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)

最佳答案

你可能需要考虑更好的逻辑。问题是,由于您在方法 def Price(): 之外使用 sBedSize、sRoomview、sVehicle,因此预计会崩溃。从 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()

关于Python,错误/Bug,打印输出两次,def/函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52883696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com