In: Computer Science
Can you write this program, but in python, I just wanna see what am I doing wrong. thank you
Instructions: The Gas-N-Clean Service Station sells gasoline and has a car wash. Fees for the car wash are $1.25 with a gasoline purchase of $10.00 or more and $3.00 otherwise. Three kinds of gasoline are available: regular at $2.89, plus at $3.09, and super at $3.39 per gallon.
User Request: Write a program that prints a statement for a customer.
Analysis: Input consists of number of gallons purchased (R, P, S, or N for no purchase), and car wash desired (Y or N). Gasoline price should be program defined constant. Sample output for these data is
Enter number of gallons and press <Enter> 9.7
Enter gas type (R, P, S, or N) and press <Enter> R
Enter Y or N for car wash and press Y
************************************** * *
* Gas-N-Clean Service Station *
* March 2, 2004 *
* * * **************************************
Amount Gasoline purchases 9.7 Gallons
Price pre gallons $ 2.89
Total gasoline cost $ 28.03
Car wash cost $ 1.25
Total due $ 29.28
Thank you for stopping
Please come again
Remember to buckle up and drive safely
#Python program that prompts for number of gallons , gas type and Y or N for car wash then print the #total due for car.
#gas.py
def main():
#gas type costs
REGULAR=2.89
PLUS=3.09
SUPER=3.39
carWashCost=0
pricePerGallon=0
gasOlineCost=0
# number of gallons from keyboard
numGallons=float(input('Enter number of gallons and press : '))
#read gas type
gasType=input('Enter gas type(R, P, S or N) and press : ')
#read Y or N for car wash
carWash=input('Enter Y or N for car wash and press : ')
#check gasType and corresponding price per gallon
if gasType=='R':
pricePerGallon=REGULAR
elif gasType=='P':
pricePerGallon=PLUS
elif gasType == 'S':
pricePerGallon = SUPER
elif gasType == 'N':
pricePerGallon = 0
#check if number of gallons is 10 or more then set car wash cost 1.25
#otherwise less than 10, set car wash cost 3.00
if numGallons >=10:
carWashCost=1.25
else:
carWashCost=3.00
#calculate teh gasoline cost
gasOlineCost=numGallons*pricePerGallon
print('************************************** * *')
print('* Gas-N-Clean Service Station *')
print('* March 2, 2004 *')
print('************************************** * *')
#calculate total due by adding gasonline cost to car wash cost
totaldue=gasOlineCost+carWashCost
#print the valus on python console with two decimal values
#{0} for first argument in format
#{0:.2f} is for print value upto two decimal values where f is for float values
print('Amount Gasoline purchases {0} Gallons'.format(numGallons))
print('Price pre gallons $ {0}'.format(pricePerGallon))
print('Total gasoline cost $ {0:.2f}'.format(gasOlineCost))
print('Car wash cost $ {0:.2f}'.format(carWashCost))
print('Total due ${0:.2f}'.format(totaldue))
print('Thank you for stopping')
print('Please come again')
print('Remember to buckle up and drive safely')
main()
Sample Output:
Enter number of gallons and press : 9.7
Enter gas type(R, P, S or N) and press : R
Enter Y or N for car wash and press : N
************************************** * *
* Gas-N-Clean Service Station *
* March 2, 2004 *
************************************** * *
Amount Gasoline purchases 9.7 Gallons
Price pre gallons $ 2.89
Total gasoline cost $ 28.03
Car wash cost $ 3.00
Total due $31.03
Thank you for stopping
Please come again
Remember to buckle up and drive safely