python代写-Basic Expressions and Statements


CS 112 – Project 1: Basic Expressions and Statements

The purpose of this assignment is to practice using basic expressions and statements, and get simple user input.

Due Date: Sunday, Feb. 3rd, 11:59pm

Extra credit 5% if submitted by Thursday, Jan 31st, 11:59pm


Programs are more interesting when they involve the user – supplying values to use in calculations, asking for names, and so on. We can get a string from the user via the input() function, and then convert to other types as needed via other built-in functions of Python, such as int(), float(), and bool().

Variables give us the chance to store values for later, recallable by name. We can even repeatedly update the value associated with that name, as a replacement: forgetting the old value forever, remembering the new value until further notice. As procedural programs are very much a sequence of executed instructions, the exact order of when we store (or replace) a value for a variable, and when we look up and use the current value, is an important part of understanding how to create the solution to a programming task.

This project will get us comfortable getting values of various types from the user and using variables while calculating different things. We'll explore control structures next, so be sure to master these more basic tasks.


A popular ice cream shop in San Diego, that is cash only and has many visitors from Mexico, wants to create a friendlier payment system for its customers and is looking for a program that can display itemized receipts and change in two currencies – US dollar (USD) and Mexican peso (MXN). Your task is to write a Python program that gets, via user input, all the necessary info of a hypothetical purchase in this shop, then calculates the respective quantities for both currencies, and finally prints the two variations of the receipt.


  1. Create your Python file

  2. When this file is run, ask questions about the ice cream purchase in the following order, storing the answers in variables as needed:

    1. What is the cost (USD) of one scoop?

    2. What is the cost (USD) of one topping?

    3. How many scoops do you want?

    4. How many toppings do you want?

    5. What is the USD/MXN exchange rate?

    6. What is the face value of the banknote (USD) you're paying with?

    7. What is your name?

  3. Print the receipt in USD

  4. Print the receipt in MXN


In computer science exact formatting of input/output is like putting on socks with shoes, while people might not do it 100% of the time in their personal life, it is extremely unusual not to do it in a professional setting. Therefore you will need to format your input/output exactly like the example below.

Pay special attention to variable types: the cost of scoop (i), the cost of topping (ii) and the exchange rate (v) are floats. The quantities (iii, iv) and the banknote value (vi) are integers. The name is string.

Also, note that for precision purposes, you’ll want to perform price calculations using floating point numbers, so make sure you use operators like / and // and %, as well as type conversions like int() and float(), appropriately in your code. Last, for better readability, make sure you round all prices to two decimals, e.g. y=round(x,2) will assign the rounded value of x to variable y.

Do not import any modules for this project such as the math module.

Do not use math.pi or math.ceil()

If you don’t know what this means, that’s alright, we’ll cover it later in the semester.

Example Run

In the example below, green text starting with '$demo' is the prompt ($demo) and the command you write to run python (python3, blue underlined text is the input given by the user, and purple text is the output that your program generates:

$demo python3

What is the cost (USD) of one scoop? 2.7 What is the cost (USD) of one topping? 0.8 How many scoops do you want? 2

How many toppings do you want? 3

What is the USD/MXN exchange rate? 19.02

What is the face value of the banknote (USD) you're paying with? 100

What is your name? George Mason

USD receipt:


* Scoops: 2 @ 2.7 = $5.4

* Toppings: 3 @ 0.8 = $2.4

  • Total: $7.8

    * Paid: $100

    * Change: $50 x 1 , $20 x 2 , $10 x 0 , $1 x 2 , $0.50 x 0 , $0.01 x 20


  • thank you George Mason!


MXN receipt:


* Coucharadas: 2 @ 51.35 = Mex$102.71

* Coberturas: 3 @ 15.22 = Mex$45.65

  • Total: Mex$148.36

  • Pagado: US$100

    * Cambio: Mex$50 x 35 , Mex$20 x 0 , Mex$10 x 0 , Mex$1 x 3 , Mex$0.50 x 1 , Mex$0.01 x 14


  • gracias George Mason!



    As we are just starting to program, and don't even have if-else statements at our disposal, we will assume many things to make the project easier, though it makes the project slightly more artificial. You may assume that:

    • The user will always enter an integer when we ask for an integer, a string when we ask for a string, etc.

    • The user will only answer with usable values. Prices won’t have negative values, etc.

    • We won’t try calculations that result in a fraction of a cent

    • The change will be as optimal as possible, e.g. $55 will break in $50, $5 instead of

      $20, $20, $10, $5

    • Both currencies have the following denomination of bills/coins: 50, 20, 10, 1, 0.5, 0.01

File Requirements, Testing, and Commenting

See the “project basics” file for details: => Resources => Resources Tab => project_basics.pdf

Testing Your First Program

The tester for this project expects exact matching to pass a test case. If you're getting the right numbers but failing test cases, check for spacing issues, capitalization, spelling errors, and so on – look closely, and you can figure it out! You get to see the exact tests we'll use when we grade your code, so you might as well get them all correct before turning in your work! No surprises there.

One note, the OUTPUT section of the tests only includes what the program is supposed to print, and does not include the characters that a user would be typing during the interaction (including when the user hits enter for a newline). This makes the output look a bit weird, but the testing file is correct. Once we learn about functions, we will jump to the real style of testing.

Grading Rubric

Submitted correctly: Code is well commented: Calculations correct:

correct input

correct USD receipt correct MXN receipt

Extra credit: TOTAL:








#see project basics file for file requirements!

#see project basics file for how to comment!

#see project basics file for how to test!

#if submitted by Thursday, Jan 31st, 11:59pm

4 Spring 2019 George Mason University



添加客服微信: abby12468