Python Forum
Calling a function to return a list of percentages
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calling a function to return a list of percentages
#4
Ok I managed to get it to print out the in the correct format but I am having trouble with printing the actual equation

So if the percentage is the user_input number * each number in taxlist / 100

I just need it to print out like this

5% tax on a Chocolate cake costing $17.50 is $0.88
10% tax on a Chocolate cake costing $17.50 is $1.75
15% tax on a Chocolate cake costing $17.50 is $2.62
20% tax on a Chocolate cake costing $17.50 is $3.50
25% tax on a Chocolate cake costing $17.50 is $4.38

And my code is now looking like this so I am just confused how to put that equation in there to get it to print out the tax result at the end for each number in the list

item = str(input("Please enter an item"))
price = float(input("Price of the item $"))
taxlist = [5,10,15,20,25]
def result (price, tax2):
    total = price * taxlist[0,1,2,3,4,4] / 100
    return total
for tax in range(5, 26, 5):
            print("",tax,"% tax on a ",item," costing ",price," is",result,"")
my output gives me a strange result too so It may just be something simple I am missing I am not sure lol

Please enter an itemCake
Price of the item $17.50
 5 % tax on a  Cake  costing  17.5  is <function result at 0x000001B4EB9201E0> 
 10 % tax on a  Cake  costing  17.5  is <function result at 0x000001B4EB9201E0> 
 15 % tax on a  Cake  costing  17.5  is <function result at 0x000001B4EB9201E0> 
 20 % tax on a  Cake  costing  17.5  is <function result at 0x000001B4EB9201E0> 
 25 % tax on a  Cake  costing  17.5  is <function result at 0x000001B4EB9201E0> 

Process finished with exit code 0
Also can someone explain why my output of the price of the item drops off the zero at the end, It should be 17.50 not 17.5
Thanks

Moderator Larz60+: Fixed tags you had wrong '\' should be '/'

No worries this has been understood and solved thanks heaps dude
Reply


Messages In This Thread
RE: Calling a function to return a list of percentages - by Liquid_Ocelot - Mar-25-2017, 10:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to sort a list with duplicates and return their unique indices. Echoroom 3 3,769 Sep-23-2022, 07:53 AM
Last Post: deanhystad
  Use of function/return Paulman 6 2,578 Oct-24-2021, 11:07 PM
Last Post: Paulman
  Multiple return from function Grimmar 7 3,752 Mar-22-2021, 09:20 PM
Last Post: Grimmar
  Lambda function not return value mbilalshafiq 4 3,571 Jul-04-2020, 07:47 AM
Last Post: ndc85430
  Child class function of Log return "None" mbilalshafiq 2 2,334 Jun-30-2020, 07:22 PM
Last Post: mbilalshafiq
  Return the sum of the first n numbers in the list. pav1983 3 4,405 Jun-24-2020, 03:37 AM
Last Post: deanhystad
  Question on "define function"; difference between return and print extricate 10 4,990 Jun-09-2020, 08:56 PM
Last Post: jefsummers
  [split] problem with function return value ops 1 3,507 Apr-13-2020, 01:48 PM
Last Post: buran
  Function to return today's month, day, and year sbabu 9 5,172 Jan-28-2020, 06:20 PM
Last Post: snippsat
  Calling a function from another function johneven 2 2,985 Jul-09-2019, 12:42 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020