Question: please solve this in python. tnx . dont use chat gpt . Programm like begginer. Task 2 0 . Solve in python. Do not copy

please solve this in python. tnx. dont use chat gpt. Programm like begginer. Task 20. Solve in python. Do not copy from chat gpt. thanks
2. Development of basic functionalities (10 points)
Define a simple Python voice dictionary where you will store the voices in memory. Define 2 voting options as keys, e.g. "blue" and "red", and set the number of points as the value, or 0 at the beginning. Define an asynchronous function vote(request) that will record the votes. The function must increment the value of one of the two options within the vote dictionary by 1. Data is sent through body of the request, and before incrementing it is necessary to check the affiliation with the Python operator
if the key from the request is in the votes dictionary, if it is not, it is necessary to return the JSON response "status": "unknown option" and status 400, if it is, it is necessary to record the vote and return \{"status": "successful voting"\} with condition 200. Define an asynchronous function current_results that will return the current state of votes as a JSON response define 2 endpoints: / vote and /results inside the calling router define the corresponding functions define 2 functions that simulate the client: vote_client(option) and results_client. Functions must simulate sending POST (to /vote) or GET (to /results) requests on the client side through ClientSession. The vote_client function receives an additional parameter option representing one of the voting options and must be sent as a JSON body of the request.
Test your server through functions to simulate client requests within the main function.
Task 21. Development of a service for sending a lot of votes. Create a new mirage.py file where you define a special service to send a large number of competing votes to the main server that processes those requests. Start by defining a function mirage_simulation that receives a single parameter number_of_requests.
If the parameter is omitted, the function must send 500 requests by default. Define within option list keys the two options you selected in Task 2, then open a new one ClientSession. Inside the ClientSession, define a loop that will execute number_requests times, while doing so
a different option is selected in each iteration of the loop. Choose the option with the random.choice function. Define the function glasaj_klient(session, option), which must simulate sending a POST request in the same way as in the first task, but now you send a reference to the session through an argument. Go back to the mirage_simulation function and define a list of tasks where you will record all the tasks that are sent inside the loop, that is, you store the client_vote(session, option) Coroutine objects. Execute the function in such a way that you will wait for the execution of all tasks in parallel. Inside the main function, call mirage_simulation with the argument 500.
Upgrade the mirage_simulation function to print the number of successes at the end requests and the number of failed requests based on the status you defined in the 2 nd task
Check the results inside the first service defined in index.py
please solve this in python. tnx . dont use chat

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!