AquaBlitz11

Gunn Jan 2 2021

Jan 2nd, 2021 (edited)
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. reminders:
  2. - please make your variable names easy to understand
  3. - if, elif, else (see examples from class)
  4. - control structures can be nested using multiple levels of indentation
  5. - tips for debugging when your program is acting weird: put a bunch of print statements in each case like when i demonstrated the concepts during class. if a variable is changed many times, maybe printing its value every single time it is changed is also a good idea to track its behavior. try a bunch of different inputs. when you have an output that's different from expected, you can carefully look for where things go wrong.
  6.  
  7. ---------------
  8.  
  9. A. Quadratic Equation
  10.  
  11. write a program that receives the following input: three float values a, b, c.
  12. these represent the equation ax^2 + bx + c = 0.
  13. your program should output all the valid real answers x.
  14.  
  15. for example, if a is 1, b is 5, c is 6, the program should output:
  16. Two Answers
  17. -2
  18. -3
  19.  
  20. you will find the power operator ** useful. for example, if you write 9**(1/2) you will get 3. (because 9 to the 1/2 is 3 aka the square root of 9.)
  21.  
  22. for now let's treat the square root of a negative number as UNDEFINED. so, make sure your program is designed in such a way that you won't accidentally take the square root of a negative number. (for fun: you can try and see what happens when you compute (-9)**(1/2) in python.)
  23.  
  24. hint: you need three cases: two answers, one answer, and no answer. recall the quadratic formula.
  25.  
  26. ---------------
  27.  
  28. B. Progressive Rate
  29.  
  30. write a program that takes in a number as an input, representing the units of electricity used in that month.
  31. calculate the electricity bill using progressive rate, meaning
  32. - the first 50 units of electricity is calculated at 0.50 $/unit
  33. - the next 100 units is calculatd at 0.75 $/unit
  34. - the next 100 units is calculated at 1.20 $/unit
  35. - any other remaining units is calculated at 1.50 $/unit
  36. after calculating, we add a surcharge of 20% before displaying the final bill.
  37.  
  38. for example, if i use 160 units. my electricity will be calcultaed as follows
  39. - first 50 units * 0.50 $/unit = 25 $
  40. - next 100 units * 0.75 $/unit = 75 $
  41. - the remaining 10 units * 1.20 $/unit = 12 $
  42. we get a total of 112$. add 20% surcharge, final bill output on the screen is 134.4.
  43.  
  44. another example: if i use 23 units. total bill output is 13.8 (from 50*0.5*1.20).
  45.  
  46. this is a rather tricky problem. you will need to carefully design the steps to achieve our program specification.
  47.  
  48. bonus points if you write a program that can be easily extended if we have additional rate increments. (think about the alternate money program solution i taught in class. we use variables to keep track of current total/remaining money to compute.)
Add Comment
Please, Sign In to add comment