Help with function on Python

This is the place for queries that don't fit in any of the other categories.

Help with function on Python

Postby jvelaz07 » Mon Oct 07, 2013 7:41 pm

I need help writing out a code which include functions. My task is as follows.

Write the two function definitions required to complete the following program. DO NOT change anything in the 'main' function. Here is what the program looks like so far (hint: try copy/paste):

Code: Select all
def main():
    show_message()
    bill_amount = float(input('Please enter the amount of the bill: $'))

    show_tip(bill_amount, 15)
    show_tip(bill_amount, 18)
    show_tip(bill_amount, 20)
    show_tip(bill_amount, 25)

main() # start the program


1. When the program is executed, the output should look as much as possible like this (user input is underlined):

Welcome to the updated tip calculator.
This program will show you several options for a tip amount.

Please enter the amount of the bill: $20

A 15% tip on a $20.00 bill amounts to $3.00.

A 18% tip on a $20.00 bill amounts to $3.60.

A 20% tip on a $20.00 bill amounts to $4.00.

A 25% tip on a $20.00 bill amounts to $5.00.

This is my current code and i know if i remove the show_message() it will run but wouldn't that be changing the main function?.

Code: Select all
def main():
    show_message()
    bill_amount = float(input('Please enter the amount of the bill: $'))

    show_tip(bill_amount, 15)
    show_tip(bill_amount, 18)
    show_tip(bill_amount, 20)
    show_tip(bill_amount, 25)



#initial statement
   
print ('Welcome to the updated tip calculator')
print ("This Program will show you several options for a tip amount.")
print()

def show_tip(bill, tip):

    #processing
    tipamount = bill * tip / 100

    #output
   
    print('\nA ' + str(tip) + '%',"tip on a $" + format(bill, '.2f') + " bill amounts to"\
          , format(tipamount,'.2f') + '.')


main()
Last edited by micseydel on Mon Oct 07, 2013 11:09 pm, edited 1 time in total.
Reason: Code tags, first post lock.
jvelaz07
 
Posts: 2
Joined: Mon Oct 07, 2013 7:19 pm

Re: Help with function on Python

Postby micseydel » Tue Oct 08, 2013 12:49 am

It looks like you need to implement it, rather than remove it.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1506
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Help with function on Python

Postby jvelaz07 » Tue Oct 08, 2013 1:16 am

So do you mean implement in the output?
jvelaz07
 
Posts: 2
Joined: Mon Oct 07, 2013 7:19 pm

Re: Help with function on Python

Postby Mekire » Tue Oct 08, 2013 1:23 am

Write the two function definitions required to complete the following program. DO NOT change anything in the 'main' function.
You need to write the function
Code: Select all
show_message
and
Code: Select all
show_tip
You seem to have written the show_tip function but instead of writing the show_message function you just made some global print calls. Put those print lines in the missing function.

-Mek
User avatar
Mekire
 
Posts: 1141
Joined: Thu Feb 07, 2013 11:33 pm
Location: Asakusa, Japan


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 8 guests