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

Zachary Ware zachary.ware+pylist at gmail.com
Wed Aug 10 14:08:34 EDT 2016


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