[Solved] SOLVED: Project #1

$25

File Name: SOLVED:_Project_#1.zip
File Size: 169.56 KB

SKU: [Solved] SOLVED: Project #1 Category: Tag:
5/5 - (1 vote)

Program Specifications 1.

Your program will prompt for two numbers (hint: use the input function): The size of the national debt in dollars (an integer). (You can look up this value online and then enter the value you find at the prompt: try http://www.brillig.com/debt_clock ) The denomination of U.S. currency bills you want to use (an integer). ($100 is the largest, common U.S. billthe curious can find more detail at http://en.wikipedia.org/wiki/Large_denominations_of_United_States_currency There is no need to check for erroneous inputwe learn that later. 2. Your program will perform some simple arithmetic calculations. 3. Your program will print out two numbers (hint: use the print function): The height in miles of your chosen bill denomination required to equal the debt number that was input (output a floating point value). The calculated distance in miles translated to a multiple of the average distance to the Earths moon (output a floating point value). Useful Facts Some useful facts: The thickness of every U.S. denomination bill is 0.0043 inches (http://www.trivialibrary.com/a/money-in-the-us-history-of-the-dollar-bill.htm) The average distance to the moon is 238,857 miles (http://en.wikipedia.org/wiki/Lunar_distance_(astronomy)) The word string in computer science has a special meaning. It means a sequence of characters, delimited by quotes. Well see it used often in our work. It differs from a number: 12 is different from 12. Assignment Notes: To input the numbers it is necessary to use the input function. The input function takes a string, a sequence of characters between quotes, as a prompt to print to the user. It then waits until the user types a response, terminated by the user typing the Enter key. A string, again as a sequence of characters, is returned. The returned string must be converted to a number. Integers for this assignment (hint: use int). A typical interaction would be something like: num_str = input(Enter a number: ) my_int = int(num_str) print is a command that will print on the Python shell window any combination of variables, values and strings. Each item to be printed must be separated from other items by a comma. All the items will be printed together, followed by a new line. For example: bills_float = 3.14159 print(The number ,bills_float, times two is , bills_float*2) This command has 4 items to print: a string (The number ), the value in the variable bills_float (3.14159), another string ( times two is ) and the result of an expression (3.14159 * 2). Thus the statement will print: The number 3.14159 times two is 6.28318 Look at the program numberInput.py in the proj01 directory as an example of using input, print and int. Once converted to numbers, the operations on these numbers are, respectively: + (sum), (difference), * (product), / (division) and % (remainder). See Chapter 1 for details. To clarify the problem specifications, we provide at the end of this document a snapshot of interaction with the already written program. Getting Started 1. Work on the problem-solving concept first, i.e. solve the problem with pencil and paper without considering Python. Use the values in the Sample Interaction below to check your work. If you cannot solve it with pencil and paper, you certainly cannot solve it using Python. Collaboration is encouraged on this step. 2. Often an easy next step is to use a sample program we provide as a starting point. a. In Spyder you can open the sample program and save it with specified assignment name (proj01.py) or create a new program (proj01.py) and copy and paste in the sample contents. b. Change the variable names to be more appropriate for this assignment. c. Change the arithmetic using the formulas you developed when you solved the problem using pencil and paper. d. Change the print statements. 3. Test your program. Begin using values from the Sample Interaction, but do more tests than that. Questions for you to consider (not hand in) 1. What happens when you try to divide by zero when you run your program (for example, enter a 0 for the bill denomination)? 2. What happens when you enter a letter instead of a number at the prompt? (Later in the course we will develop techniques to check for erroneous input.) Sample Interaction (Later in the course we will develop techniques for formatting the output to look nicer.)

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] SOLVED: Project #1
$25