Link to home
Start Free TrialLog in
Avatar of Tbalz
Tbalz

asked on

Python script is not giving desired output

Hi Guys,

I'm having an issue with a Python learning program I have written. I have refractored all my code but when I run the program with the if __main == "__main__" it says main not defined eventhough i have a function definition called main. How can I fix it? Also I'm having and issue after I create my newTrip object and want the program to run the say_hi function. All i get when i run my code is

Welcome to the Program!
<bound method Trip.say_hi of <__main__.Trip object at 0x7fcac3c4c590>>

Open in new window


My full code is below:

#!/usr/bin/python

class Trip(object):
	def __init__(self, milePerGallon, distance, pricePerGallon):
		self.milesPerGallon = milePerGallon
		self.distance = distance
		self.pricePerGallon = pricePerGallon

	def calculated_price_per_gallon(self):
		return (self.pricePerGallon * self.distance)

	def round_trip(self):
		return (self.distance * 2)

	def say_hi(self, askName):
		self.askName = raw_input("What is your name?")

	def read_float(self, mpg_text):
	#def read_float(self, mpg_text):
		mpg_text = "Vehicles Advertised Miles Per Gallon: "
		value = float(raw_input("Please enter: " +mpg_text))
		print ('%s is %f') % (self.mpg_text, self.value)
		return value

		#mpg_text = "Vehicles Advertised Miles Per Gallon: "
		#value = float(raw_input("Please enter: " +mpg_text))
		#print ('%s is %f') % (self.mpg_text, self.value)
		#return value
	def main(self):
		print "Welcome to the Program!"
		
		



#if __name__ == "__main__":
newTrip = Trip(22, 13.5, 3.27)
newTrip.main()
print newTrip.say_hi

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tbalz
Tbalz

ASKER

Wow excellent explanation! Probably the best I ever received! MANY THANKS!