python代写-Basic Expressions and Statements

  • May 15, 2020

CS 112 – Project 1: Basic Expressions and StatementsThe purpose of this assignment is to practice using basic expressions and statements, and get simple user input.Due Date: Sunday, Feb. 3rd, 11:59pmExtra credit 5% if submitted by Thursday, Jan 31st, 11:59pmBackgroundPrograms 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.ScenarioA 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.ProcedureCreate your Python fileWhen this file is run, ask questions about the ice cream purchase in the following order, storing the answers in variables as needed:What is the cost (USD) of one scoop?What is the cost (USD) of one topping?How many scoops do you want?How many toppings do you want?What is the USD/MXN exchange rate?What is the face value of the banknote (USD) you’re paying with?What is your name?Print the receipt in USDPrint the receipt in MXNGuidelinesIn 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 RunIn 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 code.pyWhat 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? 2How many toppings do you want? 3What is the USD/MXN exchange rate? 19.02What is the face value of the banknote (USD) you’re paying with? 100What is your name? George MasonUSD receipt:************************************* Scoops: 2 @ 2.7 = $5.4* Toppings: 3 @ 0.8 = $2.4Total: $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.65Total: Mex$148.36Pagado: 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!************************************AssumptionsAs 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 centThe change will be as optimal as possible, e.g. $55 will break in $50, $5 instead of$20, $20, $10, $5Both currencies have the following denomination of bills/coins: 50, 20, 10, 1, 0.5, 0.01File Requirements, Testing, and CommentingSee the “project basics” file for => Resources => Resources Tab => project_basics.pdfTesting Your First ProgramThe 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 RubricSubmitted correctly: Code is well commented: Calculations correct:correct inputcorrect USD receipt correct MXN receiptExtra credit: TOTAL:5202525255105#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:59pm4 Spring 2019 George Mason University