Preface : Master Wu, who can only stay at home on the national day, is very boring , Decided to open a Python The bakery passed the time . Every day after that , Master Wu will use a piece of code to simply realize the function of selling bread , And solve the problems exposed the day before .
Yesterday, Master Wu received complaints from customers that he had waited too long , So I made a small optimization .
""" Don't want customers to wait for complaints ,python The baker had to prepare the bread in advance ."""
import time
def preproduce():
""" Bread prepared in advance ."""
return 10
def producer():
""" Making bread ."""
time.sleep(1)
return 1
def consumer():
""" consumer , You have to say something to buy bread ."""
print("I am so happy.")
def run():
total = 0
stock = preproduce()
while True:
if stock:
# And inventory , First sell the stock of bread
consumer()
stock -= 1
else:
num = producer()
if num:
consumer()
total += num
if total >= 10:
# Shifu did it 10 A loaf of bread is coming off work .
print('Finished.')
break
if __name__ == "__main__":
run()After optimization, the customers in front can get the bread quickly , But the back customers still need to wait a long time , Master Wu, what should I do ?
Computer graduation design Python+djang student grades online course selection management system (source code + system + mysql database + Lw document)
項目介紹網絡技術的快速發展給各行各業帶來了很大的突破,也給各