From the course: Cloud Native Projects: Azure Serverless

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Solution: Python

Solution: Python

(upbeat music) - [Instructor] So now, it's time for my solution to this challenge exercise. I created a new function called coinFlip and within coinFlip, I wrote some very basic code. So first of all, I brought in logging, random and JSON. You'll see that I've changed my debug message based on my personal preference. I then get the body element from the request. I pull the count out of the body. I set heads equal to zero and tails equal to zero. Then I go for an I in the range and I flip using random int and I set flip equal to zero or one. If flip equals zero, I consider that a heads and I increment the heads. If it's a one, I assume it's tails and I increment tails. And because it can only be zero or one that else really treats it as equals one 'cause it can only be one of those two. I then create a results JSON element that includes the total count, heads, tails and then I return that as an HTTP response. I then…

Contents