In: Computer Science
Python
Create a new file named compute_cost.py.
Write your name and date in a comment.
Create a variable named base_fee and set the value to 5.5.
Prompt the user for the zone. The zones can be an integer value from 1 to any value for the zone.
Convert the zone to an integer.
Display the zone on the SenseHat with a scroll speed of 0.3, make the text blue, and the background yellow. Scroll "The zone is " and the value of the zone.
Compute the cost as follows. Be certain to use the and operator:
If the zone is between 1 and 4, the cost is the base_fee times 2.
Else if, the zone is 5 or 6, the cost is the base_fee times 1.755 plus 7.5.
Else if, the zone is 7, 8, or 9, the cost is the base_fee times 3.125 plus 9.5.
Else, the cost is the base_fee times 4.25.
Print out the cost with two decimal places of precision to the Python shell.
Print out the cost with exponential notation with one decimal place of precision to the Python shell.
Test with a zone of 2, 6, and 9.
'''
Name:<name>
Date:08-10-2020
'''
from sense_hat import SenseHat
import math
base_fee=5.5
zone=int(input("Enter Zone"))
sense = SenseHat()
blue = (0, 0, 255)
yellow = (255, 255, 0)
sense.show_message("The Zone is"+zone, text_colour=blue, back_colour=yellow, scroll_speed=0.3)
if(zone>=1 and zone<=4):
cost=base_fee*2;
elif(zone==5 or zone==6):
cost=(base_fee*1.755)+7.5
elif(zone>=7 or zone<=9):
cost=(base_fee*3.125)+9.5
else:
cost=base_fee*4.25
print("{0:.2f}".format(cost))#print cost with 2 decimal precision
print("{0:.1f}".format(math.exp(cost)))#print cost with exponential notation and 1 decimal precision
Execution output:
Note:I've commented code related to SenseHat due to my compiler restrictions.