如何重复我的代码,但下次从变量中取出一个代码?



我正在制作一个python代码,就好像我要把它放在停车场售票机上一样。它遍历所有功能 - 显示可用停车位的数量,询问车牌的最后三位数字,让您插入钱,但我不确定当我重复代码时如何从可用停车位数量中取出 1。另外,我如何在这样做时重复代码?这是我的代码:

#Import
import time
#Variables:
spaces=100
ticketprice=3
cashin=0
totalcash=0
engineer='egg'
while True:

#Beginning:
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("Harry's Car Park") 
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("There are currently", spaces,"spaces available")
reg=input("Please enter the last three digits of your registration plate > ")

#Engineer Mode
if reg==engineer:
print()
print("YOU ARE NOW IN ENGINEER MODE")
print()
ticketprice=input("What would you like to change the ticket price to? ")
print("Thank you! The ticket price has been changed to £", ticketprice)
print()
print("YOU ARE NO LONGER IN ENGINEER MODE")
print()

#Paying:
print("Please insert £"+(str(ticketprice)+" to pay for your ticket:"))
while totalcash<int(ticketprice):
cashin=int(input("Enter pound coins here £"))
totalcash=totalcash+cashin
print()
print("Thank you")
print("Amount entered=£",totalcash)

#Tickets
if totalcash>int(ticketprice):
print("Your change is £",totalcash-int(ticketprice))
print()
print("You have paid the full amount!")
print()
print("Printing Parking Ticket...")
print()
time.sleep(1)
print("     ****************************************************")
time.sleep(0.5)
print("     *                        Harry's Car Park                      ")
time.sleep(0.5)
print("     *                                                                          ")
time.sleep(0.5)
print("     *                        Ticket Price: £",(int(ticketprice)),"                   ")
time.sleep(0.5)
print("     * 16/01/2020     Reg Plate:",(reg),"        17:03   ")
time.sleep(0.5)
print("     ****************************************************")
print()

if totalcash==int(ticketprice):
print("You have paid the full amount!")
print()
print("Printing Parking Ticket...")
print()
time.sleep(1)
print("     ****************************************************")
time.sleep(0.5)
print("     *                        Harry's Car Park                      ")
time.sleep(0.5)
print("     *                                                                          ")
time.sleep(0.5)
print("     *                        Ticket Price: £",(int(ticketprice)),"                      ")
time.sleep(0.5)
print("     * 16/01/2020     Reg Plate:",(reg),"        17:03      ")
time.sleep(0.5)
print("     ****************************************************")
print()

如果只在 IF 最终块(打印票证时(使用空格 - ; 减少空格怎么办? 此外,您还应该初始化它,以便它存储最大数量的可用空间

每当客户支付机票金额时,只需写空格-=1,然后添加一个条件,如果空格==0,退出

最新更新