Question

Define a function named food which receives two parameters: an integer value representing the time of...

Define a function named food which receives two parameters: an integer value representing the time of the day measured in hours from 0 to 24 and a Boolean value indicating whether a person likes sweets (True) or not (False).

The function should return one single string with a message as follows.

  • If it is earlier than 6, the message should say "no food" (regardless of the person liking sweets or not).
  • If it is between 6 and 10 extremes included, the message should indicate "breakfast", and if the person likes sweets, additionally, after the word breakfast, there should be a comma and then the word "marmalade", otherwise (if the person does not like sweets and it is breakfast time), after the word breakfast there should be a comma and the word "coffee" (with no spaces after the comma).
  • If the time is between 11 and 15 (extremes included), the message should say "lunch", and if the person likes sweets. additionally, after the word "lunch" there will be a comma and then the word "dessert" (no spaces).
  • Similarly, if it is after 15 or before 22 the message will indicate "dinner", and similarly to lunch, if the person likes sweets there will be a comma and then the word "dessert".
  • If it is 22 or later the returned messages should be again "no food".

As an example, the following code fragment:

print (food(4,False))

should produce the output:

no food

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

The solution to your problem is:-

code for it:-

def food(k,s): # defining function food with parameters time and boolean value.
   if(k<6): # checking the time. if it is <6 printing no food.
       return("no food")
   elif(k>=6 and k<=10 and s==True): # if time is >6 and time <=10 printing break fast and if he likes sweet printing marmalade else printing coffe.
       return("breakfast,marmalade")
   elif(k>=6 and k<=10 and s==False):
       return ("breakfast,coffe")
   elif(k>=11 and k<15 and s== True): # if time is >=11 and time is<15 printing lunch and if he likes sweets printing desserts else only lunch.
       return("lunch,dessert")
   elif(k>=11 and k<15 and s==False):
       return("lunch")
   elif(k>=15 and k<22 and s==True): # if time is >=15 and time is less than 22 printing dinner and if he likes sweets printing dessert else dinner.
       return("dinner,dessert")
   elif(k>=15 and k<22 and s==False):
       return("dinner")
   elif (k>=22 and k<=24): # if time is greater the 22 then no food is available .
       return("no food")

  
                      
print(food(23,True))   # testing the fucntion.

Output for the above code is:-

Thank you.

Add a comment
Know the answer?
Add Answer to:
Define a function named food which receives two parameters: an integer value representing the time of...
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
  • In Problem Set 7 you designed and implemented a Message class. This time, let's design and...

    In Problem Set 7 you designed and implemented a Message class. This time, let's design and implement a Mailbox class in a file named Mailbox java. Do the following with this class • You may use the Message class from PS 7. You will have to add new features to the Message class from PS 7 as you work through this problem. You are welcome to start with my sample solution if you wish • Suppose there are multiple mail...

  • Case: Enron: Questionable Accounting Leads to CollapseIntroductionOnce upon a time, there was a gleaming...

    Case: Enron: Questionable Accounting Leads to CollapseIntroductionOnce upon a time, there was a gleaming office tower in Houston, Texas. In front of that gleaming tower was a giant “E,” slowly revolving, flashing in the hot Texas sun. But in 2001, the Enron Corporation, which once ranked among the top Fortune 500 companies, would collapse under a mountain of debt that had been concealed through a complex scheme of off-balance-sheet partnerships. Forced to declare bankruptcy, the energy firm laid off 4,000...

  • CASE 20 Enron: Not Accounting for the Future* INTRODUCTION Once upon a time, there was a...

    CASE 20 Enron: Not Accounting for the Future* INTRODUCTION Once upon a time, there was a gleaming office tower in Houston, Texas. In front of that gleaming tower was a giant "E" slowly revolving, flashing in the hot Texas sun. But in 2001, the Enron Corporation, which once ranked among the top Fortune 500 companies, would collapse under a mountain of debt that had been concealed through a complex scheme of off-balance-sheet partnerships. Forced to declare bankruptcy, the energy firm...

  • Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around...

    Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around risk and threat management, fostering an environment in which objectives seem clear: manage risk, manage threat, stop attacks, identify attackers. These objectives aren't wrong, but they are fundamentally misleading.In this session we'll examine the state of the information security industry in order to understand how the current climate fails to address the true needs of the business. We'll use those lessons as a foundation...

  • Read the following case: Answer the questions accordingly: PLEASE MAKE COPY PASTE AVAILABLE EEOC v. Management...

    Read the following case: Answer the questions accordingly: PLEASE MAKE COPY PASTE AVAILABLE EEOC v. Management Hospitality of Racine 666 F.3d 422 (7th Cir. 2012) OPINION BY DISTRICT JUDGE YOUNG: The Equal Employment Opportunity Commission ("EEOC") brought this action on behalf of two serv- ers, Katrina Shisler and Michelle Powell, who were em- ployed at an International House of Pancakes franchise in Racine, Wisconsin (the "Racine IHOP"), alleging that the servers were sexually harassed in violation of Title VII of...

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
ADVERTISEMENT