简体   繁体   English

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

[英]How do I repeat my code but take away one from a variable for the next time around?

I am making a python code as if I was going to put it in a car parking ticket machine.我正在制作一个 python 代码,就像我要把它放在停车场售票机一样。 It goes through all the functions - displays the number of available parking spaces, asks for the last three digits of your registration plate, gets you to insert money but I am unsure how to take 1 away from the amount of available spaces for when I repeat the code.它通过所有功能 - 显示可用停车位的数量,询问您车牌的最后三位数字,让您投入资金,但我不确定如何从可用车位数量中减去 1 重复时编码。 Also how do I repeat the code in doing so?另外我如何在这样做时重复代码? Here is my code:这是我的代码:

#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()

What if only into IF final block (when you print ticket) you use spaces--;如果只进入 IF 最后一个块(当你打印票时)你使用空格怎么办--; to reduce spaces?减少空间? Also you should initialize it so it stores the maximum amount of spaces available您还应该初始化它,以便它存储最大数量的可用空间

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎样才能把time.ctime从time.ctime拿走 - how can i take time.ctime away from time.ctime 我怎样才能从日期时间戳记中取出一纳秒,并在日期时间戳记中获得最终形式? - How can I take one nanosecond away from a datetime timestamp, and have the final form in datetime timestamp? 如何从 txt 文件中一次一行地获取数据并将其用作发送请求的变量? - How can i take data one line at a time from a txt file and use it as a variable to send requests? 我如何让 GTKOverlay 不从下面的小部件中移除所有交互? - How do I make a GTKOverlay not take ALL interaction away from widgets under? 如何重复我的初始输入代码? - How do I repeat my initial input code? 如何让我的代码循环重复? - How do I get my code to repeat in a loop? 如何从列表中取出特定数据并存储在单个变量中 - How do i take out specific data from my list and store in a individual variable 如何从 Django 中的 views.py 获取变量并将其显示在我的 HTML 页面上 - How do I take a variable from views.py in Django and display it on my HTML page 如何获取随机字符串并将其分配给变量? - How do I take my random string and assign it to a variable? 如何在不和谐中结束消息并让我的机器人重复该消息? - How do I take the end of a message on discord and make my bot repeat it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM