class logo

CS 122 - Assignment 3

ACME Widget Calculator: The ACME widget company manufactures widgets according to their customer's orders. Unfortunately, they frequently forget to ask for important details from their customers and they are lousy at calculating the total cost. This application walks through the ordering process, making sure all the required information is collected.

Here's my solution for this assignment. Note that as with all assignments, my version is not the only way to do it!

For the competency level: solution.py

For the mastery level: masterySolution.py

Posted Friday, August 7

Write a program that asks the user to enter some information about an order (see below for details), prints out the total cost, then asks the user whether they want to enter another order.

You'll need to use the raw_input function to ask the user for their input, type conversion to get what they enter to the correct type so you can do some math with it, an if statement to ask if they want to continue, and a while loop to repeat the whole thing as long as needed.

The program should collect the following bits of information

  • How many widgets are in the order? (integers only)
  • What is the brassafax ratio? (floating point number)
  • What is the cromulence level? (floating point number)
  • Add velocitators? (yes or no)

The program should then output the total cost and ask the user if they want to enter another order. The total cost is calculated as follows:

5 * numWidgets * brassafax * cromulence add 995 if add velocitators is specified

Here's what one sample run of the program looks like:

How many widgets in this order? 100 What is the brassafax ratio? .2 What is the cromulence level? 1.0 Add velocitators (yes/no)? no This order will cost 100.0 dollars Do you want to enter another order (yes or no)? no Thanks for using the ACME widget calculator!

And here's what another sample run with multiple orders looks like:

How many widgets in this order? 100 What is the brassafax ratio? .2 What is the cromulence level? 1.0 Add velocitators (yes/no)? no This order will cost 100.0 dollars Do you want to enter another order (yes or no)? yes How many widgets in this order? 100 What is the brassafax ratio? 1.5 What is the cromulence level? 0.2 Add velocitators (yes/no)? yes This order will cost 1145.0 dollars Do you want to enter another order (yes or no)? yes How many widgets in this order? 3 What is the brassafax ratio? 22 What is the cromulence level? .11 Add velocitators (yes/no)? no This order will cost 36.3 dollars Do you want to enter another order (yes or no)? no Thanks for using the ACME widget calculator!

Add file output to your program. When the program is run it should append to a file called "receipt.txt" all the information that was specified by the user as well as the total cost.

A sample receipt.txt might look like this:

Widget count = 100 Brassafax raio = 0.2 Cromulence level = 1.0 No velocitators This order will cost 100.0 dollars Widget count = 100 Brassafax raio = 1.5 Cromulence level = 0.2 Add velocitators This order will cost 1145.0 dollars Widget count = 3 Brassafax raio = 22.0 Cromulence level = 0.11 No velocitators This order will cost 36.3 dollars

Ask the user for the number of orders they want to specify, the loop through the questions for each order. Write each order to a different file, named "receipt1.txt", "receipt2.txt" and so on.

Submit your python file implementing the widget calculator

This assignment is due Thursday, July 30th, at 7:00 am

Use this form to submit your completed assignment. You can submit an assignment multiple times, and I will generally only look at the last submission. If you do submit more than once, make sure that each submission is complete on its own and doesn't rely on something you submitted previously.

Student number (no dashes):
This is the 9-digit number on your student body card. It probably starts 950 or 951 and it looks something like this: 950123456. This number is used to identify your submission so please enter it carefully.
Name (first and last):
Email address:
Notes about this assignment:
Use the notes field to mention if you worked in a group or got help with any part of the assignment. Also note if something doesn't work correctly, it shows that you know about the problem. If you don't mention it, I'll assume you didn't test your project, and thus will grade you more harshly.
Your solution to this assignment