my assignment in python


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. COMP 1030 - Computer Programming Concepts
  2. Assignment 2, Fall 2009
  3.  
  4.  
  5.  
  6. Write the Python code for the following programming problem. Please draw the corresponding flowchart also. You may do it by hand or use any software program. Raptor won�t work since it supports a repeat loop (both post-test and pre-test) where as Python only supports the while loop.
  7. Write a modular program that will calculate the cost of purchasing a meal. This program will include decisions and loops. Details of the program are as follows:
  8. � Your menu items only include the following food with accompanied price:
  9. o Yum Yum Burger = $0.99
  10. o Grease Yum Fries = $0.79
  11. o Soda Yum = $1.09
  12.  
  13. � Allow the user of the program to purchase any quantity of these items on one order.
  14. � Allow the user of the program to purchase one or more types of these items on one order.
  15. � After the order is placed, calculate the sub-totals and the total. Add a 6% sales tax to total to produce the final purchasing price.
  16. � Print to the screen a receipt showing the total of each item purchased, the sub-total of each item purchased (number purchased by price), the total, the tax and then and the final purchase price. Printing will have to be accomplished in parts in two functions as described below.
  17.  
  18. Functions:
  19. � main function that controls the program and calls on the other functions.
  20. � getOrderNumber() that inputs the order number (must be >= 0) and returns it to the main function.
  21. � takeOrderAndCalculateTotal() that takes the order, calculates the sub-totals and the total value of the order. This function also prints part of the receipt (lines 1-8 in the receipt) that involves the heading, number of items purchased, the sub-totals and total. It returns the total to the calling (main) function.
  22. � calculateTax(total) that takes as input the total and calculates the tax on it. It returns the tax calculated.
  23. � calculateFinalPrice(total, tax) and calculates the final purchase price. It also prints the rest of the receipt (lines 9-11) that involves the tax and the final purchasing price and the trailing �=�.
  24.  
  25. Notes:
  26. � The program should be well documented. Your name, date and purpose at the beginning, the purpose of each function before its definition at the minimum. Please do not clutter your code with unnecessary comments though.
  27. � The program runs while the order number is not equal to zero.
  28. � The valid input in getOrderNumber() for order number is a value >= 0. In case of invalid input, display an error message and let the user re-enter till a valid value is provided.
  29. � The only valid choices for the menu items in takeOrderAndCalculateTotal() are 1, 2 and 3. Validate the choice, giving appropriate error message in case of invalid input. Allow user to re-enter till a valid choice is input.
  30. � The number of items purchased in takeOrderAndCalculateTotal() can be from 1 through 20. Validate the input. Display error message in case of invalid input and allow user to re-enter till a valid value is entered.
  31. � The user can enter either yes or no as response to the question in takeOrderAndCalculateTotal()
  32.  
  33. Do you want to end your order? (Enter yes or no):
  34.  
  35. The corresponding loop should execute while the response is no. The condition should check for �no� though the user can input in any combination of lower or upper case (no, No etc.). Use the pre-defined function lower of the String class to check for any case-sensitive input.
  36. � Please declare and use named �constants� for the prices and the sales tax in functions where they are needed and do not use any �magic numbers� in your code, either for calculations or for displaying purposes.
  37.  
  38.  
  39. Sample Input and Output :
  40.  
  41. Please enter order number (>0). Enter 0 to stop the program : 1
  42.  
  43. START ORDER : 1
  44.  
  45. Enter 1 for Yum Yum Burger
  46. Enter 2 for Grease Yum Fries
  47. Enter 3 for Soda Yum
  48. Enter now -> 1
  49. Enter the number of burgers you want : 3
  50.  
  51. Do you want to end your order? (Enter yes or no): no
  52.  
  53. Enter 1 for Yum Yum Burger
  54. Enter 2 for Grease Yum Fries
  55. Enter 3 for Soda Yum
  56. Enter now -> 3
  57. Enter the number of sodas you want : 2
  58.  
  59. Do you want to end your order? (Enter yes or no): no
  60.  
  61. Enter 1 for Yum Yum Burger
  62. Enter 2 for Grease Yum Fries
  63. Enter 3 for Soda Yum
  64. Enter now -> 1
  65. Enter the number of burgers you want : 1
  66.  
  67. Do you want to end your order? (Enter yes or no): no
  68.  
  69. Enter 1 for Yum Yum Burger
  70. Enter 2 for Grease Yum Fries
  71. Enter 3 for Soda Yum
  72. Enter now -> 2
  73. Enter the number of fries you want : 2
  74.  
  75. Do you want to end your order? (Enter yes or no): yes
  76.  
  77. ==================== R E C E I P T ============================
  78. Number of burgers ordered :4
  79. Sub-total (@ $.99 each) :$3.96
  80. Number of fries ordered :2
  81. Sub-total (@ $.89 each) :$1.58
  82. Number of sodas ordered :2
  83. Sub-total (@ $1.09 each) :$2.18
  84. Total :$7.72
  85. Tax at 6% :$0.46
  86. Final Purchase Price :$8.18
  87.  
  88. Please enter order number (>0). Enter 0 to stop the program : 2
  89.  
  90.  
  91. START ORDER : 2
  92.  
  93. Enter 1 for Yum Yum Burger
  94. Enter 2 for Grease Yum Fries
  95. Enter 3 for Soda Yum
  96. Enter now -> 2
  97. Enter the number of fries you want : 2
  98.  
  99. Do you want to end your order? (Enter yes or no): no
  100.  
  101. Enter 1 for Yum Yum Burger
  102. Enter 2 for Grease Yum Fries
  103. Enter 3 for Soda Yum
  104. Enter now -> 3
  105. Enter the number of sodas you want : 2
  106.  
  107. Do you want to end your order? (Enter yes or no): yes
  108.  
  109. ==================== R E C E I P T =============================
  110. Number of burgers ordered :0
  111. Sub-total (@ $.99 each) :$0.00
  112. Number of fries ordered :2
  113. Sub-total (@ $.99 each) :$1.58
  114. Number of sodas ordered :2
  115. Sub-total (@ $1.09 each) :$2.18
  116. Total :$3.76
  117. Tax at 6% :$0.22
  118. Final Purchase Price :$3.98
  119.  
  120.  
  121. Please enter order number (>0). Enter 0 to stop the program : 0
  122.  
  123.  
  124.  
  125. HOW TO SUBMIT:
  126.  
  127. 1) Please submit the flowchart and the Python code (.py file) as two different attachments via blackboard link for Assignment 2.
  128. 2) Submit me a hard copy of both these attachments, with your name on it.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.