Python Vending machine [SOLVED] | Vending machine Python

import time print ("Welcome to the Python Vending Machine.") # Asking the user how much money they wish to enter. number_of_10p = int(input("How many 10 ...PythonVendingmachineHomeProgrammingForumSoftwareDevelopmentForumDiscussion/QuestionHi,iwasworkingonacodeforavendingmachineandidoconsidermyselftobeabeginner,anywayifeelmycodeismuchlongerthanitneedstobeandiwantsomeonetoshowmeanew,shorterwayofpresentingit.importtimeprint("WelcometothePythonVendingMachine.")#Askingtheuserhowmuchmoneytheywishtoenter.number_of_10p=int(input("Howmany10pencecoinswouldyouliketoinsert?"))whilenumber_of_10p<0:number_of_10p=int(input("Pleaseenterapositivenumber."))number_of_20p=int(input("Howmany20pencecoinswouldyouliketoinsert?"))whilenumber_of_20p<0:number_of_20p=int(input("Pleaseenterapositivenumber."))number_of_50p=int(input("Howmany50pencecoinswouldyouliketoinsert?"))whilenumber_of_50p<0:number_of_50p=int(input("Pleaseenterapositivenumber."))number_of_100p=int(input("Howmany1poundcoinswouldyouliketoinsert?"))whilenumber_of_100p<0:number_of_100p=int(input("Pleaseenterapositivenumber."))#Creatingavariabletostorethetotalamountofmoneyinsertedintothevendingmachine.change=round(((number_of_10p*0.10)+(number_of_20p*0.20)+(number_of_50p*0.50)+(number_of_100p*1.00)),2)#Informingtheuserhowmuchtheyhaveenteredintotal.print("\nIntotalyouhaveentered£",change)time.sleep(2)#Creatingvariablesforthe5productsandtheirrespectiveprices.product_1,product_1_price="Flake",0.55product_2,product_2_price="Wispa",0.50product_3,product_3_price="Crunchie",0.65product_4,product_4_price="MilkyWay",0.35product_5,product_5_price="Boost",0.65#Creatingvariablestotrackthenumberofeachitemsbought,flakes_bought=0wispas_bought=0crunchies_bought=0milky_ways_bought=0boosts_bought=0#Informingtheuserofthechoicesavailableandthepricesthatofeachitem.print("Thereare5productsavailabletopickfrom;\n")time.sleep(2)print("Item:{},Price{}".format(product_1,product_1_price))print("Item:{},Price{}".format(product_2,product_2_price))print("Item


常見投資理財問答


延伸文章資訊