# Calling a function with 2 arguments

Page 1 of 1

## 3 Replies - 283 Views - Last Post: 01 July 2019 - 01:25 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=416659&amp;s=990765ef0e6c9accb01c93ac019b63c7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 kbeliza

Reputation: 0
• Posts: 1
• Joined: 30-June 19

# Calling a function with 2 arguments

Posted 30 June 2019 - 06:32 PM

```[print("Welcome to the Ribbon Store!")

def total_cost(numboffeet):

numboffeet = int(input("How much ribbon do you want to buy? "))

print("Okay, you want to install", numboffeet, "feet of ribbon")

multipp = 0

if numboffeet < 10:
multipp = 0.50
elif 10 < numboffeet < 25:
multipp = 0.40
elif 25 < numboffeet < 50:
multipp = 0.30
else:
multipp = 0.20

totcost = multipp * numboffeet

print("The total cost of buying this amount of ribbon will be", totcost, "dollars")

total_cost(numboffeet)]

```

I am completely lost on the syntax of functions. I'm trying to call a function that has 2 parameters, the amount of feet and the price and then I pass them to the function. Am I on the right track?

This post has been edited by modi123_1: 30 June 2019 - 08:50 PM
Reason for edit:: In the future please use the [code] tag button in the editor

Is This A Good Question/Topic? 0

## Replies To: Calling a function with 2 arguments

### #2 andrewsw

Reputation: 6818
• Posts: 28,229
• Joined: 12-December 12

## Re: Calling a function with 2 arguments

Posted 01 July 2019 - 12:47 AM

Where is your attempt to provide two arguments?

What material are you studying?

### #3 jon.kiparsky

• Beginner

Reputation: 11651
• Posts: 19,801
• Joined: 19-March 11

## Re: Calling a function with 2 arguments

Posted 01 July 2019 - 07:31 AM

Can you be more precise about your question? The syntax of functions is pretty straightforward: you define them with a def, whatever's indented under the def is the body of the function, you return something or a None is returned for you... pretty simple. Calling them, you use the name of the function, open parenthesis, args and kwargs, close paren, and at execution time that call is replaced by the return value of the function, whatever that might turn out to be.

### #4 baavgai

• Dreaming Coder

Reputation: 7482
• Posts: 15,508
• Joined: 16-October 07

## Re: Calling a function with 2 arguments

Posted 01 July 2019 - 01:25 PM

First, this fundamentally makes no sense:
```def total_cost(numboffeet):
numboffeet = int(input("How much ribbon do you want to buy? "))

```

Why are you passing a value name that you are both overwriting and not using? Which, in turn, is probably your issues with:
```total_cost(numboffeet)

```

Because you haven't defined that variable name yet.

So, two birds with one stone:
```def total_cost(numboffeet):
# use the value passed
print("Okay, you want to install", numboffeet, "feet of ribbon")

# ask the user for a value here
feet = int(input("How much ribbon do you want to buy? "))
# pass that value to a function
total_cost(feet)

```

Changing little more than the order of your code, and adding the new concept of return, you can do this:
```def total_cost(numboffeet):
multipp = 0
if numboffeet < 10:
multipp = 0.50
elif 10 < numboffeet < 25:
multipp = 0.40
elif 25 < numboffeet < 50:
multipp = 0.30
else:
multipp = 0.20
# totcost = multipp * numboffeet
return multipp * numboffeet

def main():
print("Welcome to the Ribbon Store!")
numboffeet = int(input("How much ribbon do you want to buy? "))
print("Okay, you want to install", numboffeet, "feet of ribbon")
print("The total cost of buying this amount of ribbon will be", total_cost(numboffeet), "dollars")

main()

```

Or, perhaps:
```def feet_multiplyer(feet):
if feet < 10:
return 0.50
if feet < 25:
return 0.40
if feet < 50:
return 0.30
return 0.20

def total_cost(feet):
return feet * feet_multiplyer(feet)

```

Hope this helps.