Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reminders:
- - please make your variable names easy to understand
- - if, elif, else (see examples from class)
- - control structures can be nested using multiple levels of indentation
- - 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.
- ---------------
- A. Quadratic Equation
- write a program that receives the following input: three float values a, b, c.
- these represent the equation ax^2 + bx + c = 0.
- your program should output all the valid real answers x.
- for example, if a is 1, b is 5, c is 6, the program should output:
- Two Answers
- -2
- -3
- 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.)
- 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.)
- hint: you need three cases: two answers, one answer, and no answer. recall the quadratic formula.
- ---------------
- B. Progressive Rate
- write a program that takes in a number as an input, representing the units of electricity used in that month.
- calculate the electricity bill using progressive rate, meaning
- - the first 50 units of electricity is calculated at 0.50 $/unit
- - the next 100 units is calculatd at 0.75 $/unit
- - the next 100 units is calculated at 1.20 $/unit
- - any other remaining units is calculated at 1.50 $/unit
- after calculating, we add a surcharge of 20% before displaying the final bill.
- for example, if i use 160 units. my electricity will be calcultaed as follows
- - first 50 units * 0.50 $/unit = 25 $
- - next 100 units * 0.75 $/unit = 75 $
- - the remaining 10 units * 1.20 $/unit = 12 $
- we get a total of 112$. add 20% surcharge, final bill output on the screen is 134.4.
- another example: if i use 23 units. total bill output is 13.8 (from 50*0.5*1.20).
- this is a rather tricky problem. you will need to carefully design the steps to achieve our program specification.
- 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