0

Pretty much I am trying to use the user inputs gotten in the sales function in the addVat function

Sales_Figures = []

def sales():
    num = int((input("Please enter sales figures: ")))
    Sales_Figures = [num]
    while num != -1:
        num = int(input("Please enter sales figures: "))
        Sales_Figures.append(num)

    print("The sales figures entered were:", end=" ")
    for num in Sales_Figures:
        if num != -1:
            print(num, end=", ")

    print("The sales figures including VAT are")
    return Sales_Figures

def addVat():

sales()
1
  • 2
    A key feature of functions is that they can take arguments. I suggest looking into some Python tutorials on functions. Commented Nov 9, 2019 at 21:27

2 Answers 2

1

You can simply put return parameter of sales() function in a variable and then pass it to addVat()

Sales_Figures = []

def sales():
    while num != -1:
        num = int(input("Please enter sales figures: "))
        Sales_Figures.append(num)

    print("The sales figures entered were:", end=" ")
    for num in Sales_Figures:
        if num != -1:
            print(num, end=", ")

    print("The sales figures including VAT are")
    return Sales_Figures
saleFigures= sales()
def addVat(saleFigures):
Sign up to request clarification or add additional context in comments.

Comments

0

The problem with the given code snippet is that you override Sales_Figures. You can either remove the second line:

Sales_Figures = [num]

That is, define your method as follows (in this solution you don't need to return the list, as it is defined outside):

def sales():
    num = 0
    while num != -1:
        num = int(input("Please enter sales figures: "))
        Sales_Figures.append(num)

    print("The sales figures entered were:", end=" ")
    for num in Sales_Figures:
        if num != -1:
            print(num, end=", ")

    print("The sales figures including VAT are")

Alternatively you can define Sales_Figures inside the method and the return it:

def sales():
    num = 0
    Sales_Figures = []
    while num != -1:
        num = int(input("Please enter sales figures: "))
        Sales_Figures.append(num)

    print("The sales figures entered were:", end=" ")
    for num in Sales_Figures:
        if num != -1:
            print(num, end=", ")

    print("The sales figures including VAT are")
    return Sales_Figures

As you now invoke the method, use the return value

Sales_Figures = sales()

Finally, VAT_RATE = 1.05 def addVat(s): return [VAT_RATE*x for x in s]

addVat(Sales_Figures)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.