Question

THis is Python Write an overseerSystem function that has a kwargs argument. Within the function, see...

THis is Python

Write an overseerSystem function that has a kwargs argument.

Within the function, see if the keyword temperature exists in kwargs. If it does, and the temperature is greater than 500, print a warning with the temperature.
Also see if the keyword CO2level exists in kwargs. If it does, and the CO2level is greater than .15, print a warning with the CO2level.
Lastly, see if the keyword miscError exists in kwargs. If it does, print a warning with the miscError number.

Test from main by creating five messages and calling the overseerSystem function with each message.

Message1 is temperature:550
Message2 is temperature:475
Message3 is temperature:450, miscError:404
Message4 is CO2level:.18
Message5 is CO2level:.2, miscError:418

Sample Execution Results:

Warning: temperature is 550
Misc error #404
Warning: CO2level is 0.18
Warning: CO2level is 0.2
Misc error #418

Thank you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

# overseerSystem function definition
def overseerSystem(**kwargs):
   for i in kwargs: # loop for iterate through every keyword in kwargs
       # Checks whether the keyword temperature exists in kwargs
       if(i=="temparature"):
           # # Checks whether the CO2level is greater than 500
           if(kwargs[i]>500):
               print("Warning: temperature is",kwargs[i]) # Prints Warning
       # Checks whether the keyword CO2level exists in kwargs
       if(i=="CO2level"):
           # Chechs whether the CO2level is greater than .15
           if(kwargs[i]>.15):
               print("Warning: CO2level is",kwargs[i]) # Prints Warning
       # Checks whether the keyword miscError exists in kwargs
       if(i=="miscError"):
           print("Misc error #"+str(kwargs[i])) # Prints miscError

# calling the overseerSystem function with each message.
overseerSystem(temparature = 550)
overseerSystem(temparature = 475)
overseerSystem(temparature = 450,miscError = 404)
overseerSystem(CO2level = .18)
overseerSystem(CO2level = .2,miscError = 418)

CODE ATTACHMENTS:

OUTPUT:

SUMMARY:

We can use **kwargs to let your functions take an arbitrary number of keyword arguments ("kwargs" means "keyword arguments")

First we check the given keywords does exist or not in kwargs.

If it does, we check for the conditions given for that corresponding keyword.

And Print Output in required format.

PLEASE 'LIKE' MY SOLUTION AND COMMENT IF YOU HAVE ANY DOUBTS.

Add a comment
Know the answer?
Add Answer to:
THis is Python Write an overseerSystem function that has a kwargs argument. Within the function, see...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT