协助/审查我的python 3虚拟巴士的座位问题

Tha*_*Guy 4 python python-3.x

当前脚本为站立状态

totSeat = 100

print("Seats Remaining", totSeat, end = " ")
gSeat = int(input("How many in your group?"))
while gSeat != 100:
    totSeat -= gSeat
    if gSeat <= 100:
        print("Booked, Thank You")
        print("Seats Remaining", totSeat, end=" ")
        gSeat = int(input("How many in your group?"))
        if totSeat <= 1:
            print("Booked, Thank You\nSOLD OUT")
            break
    if gSeat < totSeat:
        print("Sorry, not enough seats left.")
        gSeat = int(input("How many in your group?"))
Run Code Online (Sandbox Code Playgroud)

基本上

如果“ totSeat”(总席位)为0,我需要打破并说售罄。如果“ gSeat”(宾客座位)在“ totSeat”之上(包括使用输入101+的情况),我需要显示“对不起,座位不足”。

就像站立一样,它有点像这样,但是变得有些笨拙,甚至在跌破之前陷入可用的-1个座位。我对python非常陌生,因为它对真正粗糙的脚本表示歉意

小智 5

这是您可能需要的脚本,

totSeat = 100

print("Seats Remaining", totSeat, end = " ")

while totSeat > 0:
    gSeat = int(input("How many in your group?"))
    if gSeat > totSeat:
        print("Sorry, not enough seats left.")
    else:
        totSeat-=gSeat
        print("Booked, Thank You")
        print("Seats Remaining", totSeat, end=" ")
print("Sold out")
Run Code Online (Sandbox Code Playgroud)