Code Point
July 31, 2010, 10:58:07 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Geshi Sintax Hilighting Mod Installed. Tens of languages available.
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: mileage_while.py tutorial question  (Read 3033 times)
fuston05
Jr. Member
*

Karma: 0
Offline Offline

Posts: 14


« on: February 06, 2008, 03:41:23 PM »

we put the command gallon_price=gallon price +0.5, to raise price. does it have to be "after" the final print lines?
im new to this and i need to know if the order in wich these commands r scripted matters and to what extent.?
this is very intersting, its like a got the "fever" for this now.lol
Logged
Alter Lobo
Global Moderator
Jr. Member
*****

Karma: 10
Offline Offline

Posts: 65


« Reply #1 on: February 06, 2008, 09:18:37 PM »

Post your code between (code)(/code) tags so I can understand what exactly are you doing.
Logged
fuston05
Jr. Member
*

Karma: 0
Offline Offline

Posts: 14


« Reply #2 on: February 07, 2008, 04:59:41 AM »

(code)print
print "This program calculates a car mileage"
print "and its cost for a price range"
print

distance = float(raw_input("How many miles were measured ? "))
print
consumed = float(raw_input("How many gallons of gas were consumed ? "))

mpg = distance / consumed

print
print "mileage is", mpg, "miles per gallon"
print

# the while instruction tells the computer to "loop" through
# all indented lines below it "while" something is true
#
# in this case it will loop while the gallon price is lower then US$ 2.49

gallon_price = 2.20

while gallon_price < 2.49:
   cost = gallon_price / mpg
   print 'When the gallon price is US$', gallon_price,
   print "the cost is US$", cost, "per mile"

   # here we raise the gallon price
   gallon_price = gallon_price + 0.05

print(/code)

this is wat im working on, its from the tutorial on  http://programming-crash-course.com/the_while_loop. on this one were adding the "while loop"
can the last line wich adds"+0.05" to price be put ex: before "while loop"? or does it have to be after?
« Last Edit: February 07, 2008, 05:02:05 AM by fuston05 » Logged
Alter Lobo
Global Moderator
Jr. Member
*****

Karma: 10
Offline Offline

Posts: 65


« Reply #3 on: February 07, 2008, 08:15:02 AM »

When it is inside the loop it will be added at every iteration of the loop. If you put it outside then it will only be added once.

The real tag for Python code is:

[code=Python][/code]
« Last Edit: February 07, 2008, 08:26:13 AM by Alter Lobo » Logged
fuston05
Jr. Member
*

Karma: 0
Offline Offline

Posts: 14


« Reply #4 on: February 07, 2008, 09:44:33 PM »

ok, i get it, now it really seems like it was dumb Q..lol..tyvm
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!