Instantly share code, notes, and snippets.

@mastro35 /nocache.py Secret
Created Apr 13, 2018

Embed
What would you like to do?
import time
import datetime
def get_candy_price(candy_id):
# let's use a sleep to simulate the time your function spends trying to connect to
# the web service, 5 seconds will be enough.
time.sleep(5)
# let's pretend that the price returned by the web service is $1 for candies with a
# odd candy_id and $1,5 for candies with a even candy_id
price = 1.5 if candy_id % 2 == 0 else 1
return (datetime.datetime.now().strftime("%c"), price)
# now, let's simulate 20 customers in your show.
# They are asking for candy with id 2 and candy with id 3...
for i in range(0,20):
print(get_candy_price(2))
print(get_candy_price(3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment