Why can't I define a variable like "miles_driven" with an underscore in Python 3.4.3 ?

Cai Gengyang gengyangcai at gmail.com
Wed Aug 10 16:57:02 EDT 2016


Yea, using IDLE on OSX, Python 3.4.3. 

Yeah it works now ... I had to increase the font size and the indentation width. When that happened , it could define miles_driven 




On Thursday, August 11, 2016 at 2:09:11 AM UTC+8, Zachary Ware wrote:
> On Wed, Aug 10, 2016 at 12:39 PM, Cai Gengyang <gengyangcai at gmail.com> wrote:
> > I managed to get this piece of code to work :
> >
> >>>> print("This program calculates mpg.")
> > This program calculates mpg.
> >>>> milesdriven = input("Enter miles driven:")
> > Enter miles driven: 50
> >>>> milesdriven = float(milesdriven)
> >>>> gallonsused = input("Enter gallons used:")
> > Enter gallons used: 100
> >>>> gallonsused = float(gallonsused)
> >>>> gallonsused = float(gallonsused)
> >>>> mpg = milesdriven / gallonsused
> >>>> print("Miles per gallon:", mpg)
> > Miles per gallon: 0.5
> >>>> print("This program calculates mpg.")
> > This program calculates mpg.
> >>>> milesdriven = input("Enter miles driven:")
> > Enter miles driven: 100
> >>>> milesdriven = float(milesdriven)
> >>>> gallonsused = input("Enter gallons used:")
> > Enter gallons used: 500
> >>>> gallonsused = float(gallonsused)
> >>>> mpg = milesdriven / gallonsused
> >>>> print("Miles per gallon:", mpg)
> > Miles per gallon: 0.2
> >
> > But, why can't i define a variable like "miles_driven" with an underscore in my Python Shell ? When I try to define it , the underscore doesn't appear at all and instead I get this result :
> > "miles driven" , with no underscore appearing even though I have already typed "_" between "miles" and "driven" ?
> 
> Are you using IDLE on OSX?  Try changing your font or bumping up the
> size (or switch to 3.5.2, which has better defaults).
> 
> -- 
> Zach



More information about the Python-list mailing list