I can't seem to understand why I cannot run this.
Please explain.
Thank you in advance.

#07/22/2010
#Write a program that will calculate a 20% tip and a 6%
#sales tax on a meal price. The user will enter the meal price
#and the program will calculate tip, tax, and the total.
#the total is the meal price plus the tip plus the tax.

#main function

def main():
    print 'Welcome to the meal calculator program'
    print
    
mealprice = input_meal()
tip = calc_tip(mealprice)
tax = calc_tax(mealprice)
total = calc_total(mealprice, tip, tax)
print_info(mealprice, tip, tax, total)

#this function will input meal price
def input_meal():
    mealprice = input('Enter the meal price $')
    mealprice = float(mealprice)
    return mealprice
#calls mealprice

#this function will calculate tip at 20%
def calc_tip(mealprice):
    tip=mealprice * .20
    return tip
#calls tip

#this function will calculate tax at 6%
def calc_tax(mealprice):
    tax = mealprice * .06
    return tax
#calls tax

#this function will calculate tip, tax, the mealprice
#and the total.
def calc_total(mealprice,tip,tax):
    total = mealprice + tip + tax
    return total
#calls total

#this function will print tip, tax, the mealprice
#and the total.
def print_info(mealprice,tip,tax,total):
    
    print 'The mealprice is $' , mealprice
    print 'The tip amount is $' , tip
    print 'The tax amount is $', tax
    print 'The total amount for your evening is $', total
    
#calls main
main()

You were trying to call functions before they were defined, take a look and pm me if you dont understand. Define your functions - THEN call them. Good luck on future projects.

#07/22/2010
#Write a program that will calculate a 20% tip and a 6%
#sales tax on a meal price. The user will enter the meal price
#and the program will calculate tip, tax, and the total.
#the total is the meal price plus the tip plus the tax.

#main function

def main():
    print 'Welcome to the meal calculator program'
    print

#this function will input meal price
def input_meal():
    mealprice = input('Enter the meal price $')
    mealprice = float(mealprice)
    return mealprice
#calls mealprice

#this function will calculate tip at 20%
def calc_tip(mealprice):
    tip=mealprice * .20
    return tip
#calls tip

#this function will calculate tax at 6%
def calc_tax(mealprice):
    tax = mealprice * .06
    return tax
#calls tax

#this function will calculate tip, tax, the mealprice
#and the total.
def calc_total(mealprice,tip,tax):
    total = mealprice + tip + tax
    return total
#calls total

mealprice = input_meal()
tip = calc_tip(mealprice)
tax = calc_tax(mealprice)
total = calc_total(mealprice, tip, tax)

#this function will print tip, tax, the mealprice
#and the total.
def print_info(mealprice,tip,tax,total):

    print 'The mealprice is $' , mealprice
    print 'The tip amount is $' , tip
    print 'The tax amount is $', tax
    print 'The total amount for your evening is $', total

print_info(mealprice, tip, tax, total)

#calls main
main()

Thank you!
I am new to this and could not determine "who's on first."

You were trying to call functions before they were defined, take a look and pm me if you dont understand. Define your functions - THEN call them. Good luck on future projects.

#07/22/2010
#Write a program that will calculate a 20% tip and a 6%
#sales tax on a meal price. The user will enter the meal price
#and the program will calculate tip, tax, and the total.
#the total is the meal price plus the tip plus the tax.

#main function

def main():
    print 'Welcome to the meal calculator program'
    print

#this function will input meal price
def input_meal():
    mealprice = input('Enter the meal price $')
    mealprice = float(mealprice)
    return mealprice
#calls mealprice

#this function will calculate tip at 20%
def calc_tip(mealprice):
    tip=mealprice * .20
    return tip
#calls tip

#this function will calculate tax at 6%
def calc_tax(mealprice):
    tax = mealprice * .06
    return tax
#calls tax

#this function will calculate tip, tax, the mealprice
#and the total.
def calc_total(mealprice,tip,tax):
    total = mealprice + tip + tax
    return total
#calls total

mealprice = input_meal()
tip = calc_tip(mealprice)
tax = calc_tax(mealprice)
total = calc_total(mealprice, tip, tax)

#this function will print tip, tax, the mealprice
#and the total.
def print_info(mealprice,tip,tax,total):

    print 'The mealprice is $' , mealprice
    print 'The tip amount is $' , tip
    print 'The tax amount is $', tax
    print 'The total amount for your evening is $', total

print_info(mealprice, tip, tax, total)

#calls main
main()

In Python you can call the function, which is defined after another without forward definitions. However the function must be defined before main code calls it. It is bad practise to put main code before definitions except for some variable definitions.

def a(p):
    if p>4:
        b(p)
    else:
        print "a",

def b(p):
    print "b",


for parameter in range(10):
    a(parameter)

c(5) # error


def c(p):
    print "c"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.