Vending machine help | Vending machine Python

The official dedicated python forum. ... Hi, I have a project to build a vending machine that must display items and balance of coins within ...VendingmachinehelpPythonForumPythonCodingHomeworkThreadRating:0Vote(s)-0Average12345ThreadModesVendingmachinehelpwigglesProgrammernamedTimPosts:9Threads:3Joined:Apr2020Reputation:0#1Apr-03-2020,01:09AMHi,Ihaveaprojecttobuildavendingmachinethatmustdisplayitemsandbalanceofcoinswithinthemachine.Ihavedonesomeworkonitandamstuckonline31ofmycode.Ihavedefinedself.totalhoweveritiscomingbackasaninvalidsyntax?IamhappyforyoutocritiquemycodehoweverIamcompletelynewtothis,andIamtryingtokeepitsimple.IhaveonlycompletedthecodeforoneitemsofarinmymachineThanksinadvance!classVending_Machine(object):aussie_coins=(0.05,0.10,0.20,0.50,1.00,2.00)items=['Tea','Coffee','Coke','OrangeJuice']item_price=[0.50,1.00,1.50,1.00]item_code=[1,2,3,4]def__init__(self):self.total=0.00definsert_coin(self,coin):iffloat(coin)notin(self.aussie_coins):print('TheVendingMachineacceptsonly:{}.'.format(self.aussie_coins),end='')else:self.total+=coinprint('Currentlythereisatotalof{:.2f}inmachine'.format(self.total))defmenu():print("WelcometomyVendingMachine")print(item_code[0],items[0],item_price[0])#usingthedict.fromvendingmachineclassprint(item_code[1],items[1],item_price[1])print(item_code[2],items[2],item_price[2])print(item_code[3],items[3],item_price[3])defuser_input(self,choice):choice=input("Pleaseentertheitemcodeofanitemyouwouldliketopurchase:")ifchoice==item_code[0]:print("Youhaveselected{}-thepriceis${.2f}.Currentlyyouhaveatotalof${.2f}inthemachine.".format(items[0],item_price[0],self.total))whileself.total=item_price[0]:self.total-=item_price[0]print('Pleasetakeyour{}.Totalof{:.2f}inthemachine'.format(items[0],self.total))ReplyFindReplyndc85430.Posts:1,465Threads:1Joined:Apr2017Reputation:78#2Apr-03-2020,03:50AMYoudon'thaveconditionsinelsestatements(lin


常見投資理財問答


延伸文章資訊