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 Solve in python. Do not copy from chat gpt thanks
Development of basic functionalities points
Define a simple Python voice dictionary where you will store the voices in memory. Define voting options as keys, eg "blue" and "red", and set the number of points as the value, or at the beginning. Define an asynchronous function voterequest that will record the votes. The function must increment the value of one of the two options within the vote dictionary by 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 if it is it is necessary to record the vote and return status: "successful voting" with condition Define an asynchronous function currentresults that will return the current state of votes as a JSON response define endpoints: vote and results inside the calling router define the corresponding functions define functions that simulate the client: voteclientoption and resultsclient. Functions must simulate sending POST to vote or GET to results requests on the client side through ClientSession. The voteclient 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 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 miragesimulation that receives a single parameter numberofrequests.
If the parameter is omitted, the function must send requests by default. Define within option list keys the two options you selected in Task then open a new one ClientSession. Inside the ClientSession, define a loop that will execute numberrequests 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 glasajklientsession 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 miragesimulation 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 clientvotesession 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 miragesimulation with the argument
Upgrade the miragesimulation 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 nd task
Check the results inside the first service defined in index.py
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
