By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,630 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,630 IT Pros & Developers. It's quick & easy.

gallons

P: 64
i have to Write a program that asks the user to input
The capacity in gallons of a fuel tank
The fuel efficiency in miles per gallon
The price of a gallon of petrol

below is the code that i have written, can anyone double cheak, and to see wht can be changed and how it can be improved.i have also attched txt file, in order to see it clearer

Expand|Select|Wrap|Line Numbers
  1. print "----welcome----"
  2.  
  3.  
  4. capacity = input ("please enter the capacity of the fuel tank in gallons, gallons must be between 6 & 20:")
  5. while capacity < 6 or capacity > 20:
  6.  capacity = input ("sorry invalid number,please enter gallons  between 6 & 20:")
  7.  
  8.  
  9.  
  10.  
  11. efficiency = input ("please enter the fuel efficiency in MPG, efficiency must be between 20 & 75:")
  12. while efficiency < 20 or efficiency > 75:
  13.     efficiency = input("sorry invalid number,please enter MPG  between 20 & 7:")
  14.  
  15. pricepergallon=input ("price per gallon of petrol? , price must be between 3.20&4.20:")
  16.  
  17. while pricepergallon < 3.20 or pricepergallon > 4.20:
  18.  pricepergallon= input ("sorry invallid price,please enter price between 3.20 & 4.20:")
  19.  
  20. carcango= capacity * efficiency
  21.  
  22. print " on a full tank, the car can travel" ,carcango, "miles"
  23.  
  24. print "the cost of travelling 100 miles is ", (100.0/efficiency *pricepergallon)
  25.  
  26. print "end of program" 
Attached Files
File Type: txt gallons1.txt (949 Bytes, 344 views)
Dec 17 '08 #1
Share this Question
Share on Google+
3 Replies


P: 64
please is there anyone who can help with this question
Dec 18 '08 #2

boxfish
Expert 100+
P: 469
As far as I can tell, your program is fine; what do you want help with?
Dec 18 '08 #3

P: 64
to make it look more effecint, and if you can give suggestion on how to re-word it.
Dec 19 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.