1. Python assignment

  • Ask the user for their name, then say hello, addressing the user by name
  • Explain to the user that you are selling items, and ask the user if they want to purchase anything. If the user says yes, continue with the program. If the user says no, say goodbye to the user and end the program. Otherwise, inform the user that their input is invalid and let the program end.
  • List at least 3 items you are selling, and ask the user what they would like to buy. If the user does not choose a valid option, inform the user and let the program end.
  • Ask the user how much money they have. If the user enters a negative number, inform the user that their input is invalid and let the program end.
  • Decide how much your items cost (they can all cost the same, or they can cost different amounts -- up to you!). If the user has enough money to pay for the item they chose, print a message confirming that they have purchased the item. If the user does not have enough money, print a message to inform them.
  • Please make sure to give clear instructions about what input your user should enter. For example, "Enter yes or no" or "Enter numbers between 1 and 5" (see Example Output).
  • Hint: You will need to validate input and use nested ifs for this assignment!

2. Be sure to add comments for each section of your code.

3. Make sure your output is descriptive. Tell the user what you're printing, don't just print out the answers alone.

4. Your program should not use code/concepts we have not yet covered. You must demonstrate that you have mastered the concepts covered in class.

5.Remember to always begin your code with the following documentation comments.

Example Output

Hi, there! What's your name?
John

Nice to meet you, John
I'm selling different food items.
Are you interested in buying anything today? (Please enter yes or no.)
yes

Awesome! Here are the things I'm selling:
1. spicy ahi poke bowl
2. grilled cheese sandwich
3. 1 pound of green grapes
4. a half-eaten chocolate chip cookie (sorry)
5. steak and lobster
What would you like to purchase? (Enter 1, 2, 3, 4, or 5)
100

Invalid input. That wasn't one of the choices!
Try again next time.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.