Apr-11-2020, 10:10 PM
Hi,
This is my first def function and i cannot figure out why i get a, Nameerror: name 'mpg' is not defined. Any help is much appreciated!!.
This is my first def function and i cannot figure out why i get a, Nameerror: name 'mpg' is not defined. Any help is much appreciated!!.

#!/usr/bin/env python3 def calculateMPG(milesDriven,gallonsUsed): mpg=milesDriven/gallonsUsed mpg=round(mpg,1) return mpg def main(): choice='y' while choice.lower()=='y': #get input form user milesDriven=float(input('enter miles driven')) gallonsUsed=float(input('enter gallons used')) #call MPG function calculateMPG(milesDriven,gallonsUsed) print('miles per gallon:\t',mpg) #determine fate of loop choice=input('do you want to continue: y/n')