Advertisement
Guest User

income calculating

a guest
Oct 8th, 2015
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. Description of the task
  2.  
  3. John needs to rise money for his education, so he gets a job in selling magazine subscriptions by phone. The base salary for this job is $40 per day. If he sells more than 10 subscriptions in any day, but not more than 20, he gets extra $5 for each subscription over 10-subscription limit (for example, if he sells 16, i.e., 6 more than 10, he will receive extra 6 * $5 = $30 on this day in addition to the basic salary of $40). If he has sold more than 20 subscription in any given day, he stills receives $5 for each subscription between 11 and 20, and then also $10 for each subscription above 20. (For example, 27 subscriptions sold in a day produce 7 * $10 + 10 * $5 = $120 , plus $40 of the basic salary). The salary is therefore calculated separately for each work day.
  4.  
  5. To make sure that he is paid correctly for his job, he needs a salary calculator. Your task is to write a salary calculator program for John. The program should ask to enter the volume of subscriptions sold day by day for a number of consecutive days and then calculate the total salary for these days. The program should allow John to stop entering data and calculate salary anytime he wants, so instead of asking John to say how many days he wants to process in advance, the program should advise John to enter negative number to stop and use this negative number to end data input and calculate salary. Of course, you should not treat this negative number as a volume of sales, it is just a signal that input is over. See below three examples of data input and salary calculation.
  6.  
  7. Tip: Remember about pre-reading pattern in input processing! Reading data for the first day should be done before the loop. The remaining data should be read within the loop as in the examples that we discussed in class.
  8.  
  9. User input and handling errors
  10.  
  11. No need to handle input errors. You can assume that the user provides their sales volumes in different days as integers and that the numbers provided by the user are reasonable.
  12.  
  13. Three examples of program execution:
  14.  
  15. [program execution begins]
  16.  
  17. Enter the volume of subscriptions sold on different days.
  18. Enter negative value to stop.
  19. Enter the first day sales.
  20. 10
  21. Enter the next-day sales.
  22. 15
  23. Enter the next-day sales.
  24. 8
  25. Enter the next-day sales.
  26. 22
  27. Enter the next-day sales.
  28. -5
  29. Your salary is $255.
  30. [Program execution ends]
  31. [program execution begins]
  32. Enter the volume of subscriptions sold on different days.
  33. Enter negative value to stop.
  34. Enter the first day sales.
  35. 0
  36. Enter the next-day sales.
  37. 8
  38. Enter the next-day sales.
  39. 4
  40. Enter the next-day sales.
  41. 0
  42. Enter the next-day sales.
  43. -5
  44. Your salary is $160.
  45. [Program execution ends]
  46. [program execution begins]
  47. Enter the volume of subscriptions sold on different days.
  48. Enter negative value to stop.
  49. Enter the first day sales.
  50. -8
  51. Your salary is $0.
  52. [Program execution ends]
  53.  
  54.  
  55.  
  56.  
  57.  
  58. -----------------------------------------------------------------------------------------------------------------------------
  59.  
  60.  
  61. MY CODE
  62.  
  63.  
  64.  
  65. def main():
  66.  
  67. print "Enter the volume of subscriptions sold on different days.\nEnter negative value to stop."
  68. first = input("Enter the first day sales.\n")
  69. difference = first - 10
  70. sum = 0
  71.  
  72. if first >= 0:
  73. if difference <= 0:
  74. sum += 40
  75. elif difference < 10:
  76. sum += (40 + difference * 5)
  77. elif difference >= 10:
  78. sum += (40 + (difference-10) * 10 + 50)
  79.  
  80. number = input("Enter the next-day sales.\n")
  81. difference2 = number - 10
  82. while number >= 0:
  83. if difference2 <= 0:
  84. sum += 40
  85. number = input("Enter the next-day sales.\n")
  86. elif difference2 < 10:
  87. sum += (40 + difference2 * 5)
  88. number = input("Enter the next-day sales.\n")
  89. elif difference2 >= 10:
  90. sum += (40 + (difference2-10) * 10 + 50)
  91. number = input("Enter the next-day sales.\n")
  92. else:
  93. print "Your salary is $"+str(sum)+"."
  94. else:
  95. print "Your salary is $"+str(sum)+"."
  96.  
  97. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement