0
# Profit and Loss
# Function to calculate Profit.

def Profit(costPrice, sellingPrice):
    profit = (sellingPrice - costPrice)

    return profit


# Function to calculate Loss.
def Loss(costPrice, sellingPrice):
    Loss = (costPrice - sellingPrice)

    return Loss

if __name__ == "__main__":

    input(costPrice, sellingPrice)

    if sellingPrice == costPrice:
        print("No profit nor Loss")

    elif sellingPrice > costPrice:
        print(Profit(costPrice,
                     sellingPrice), "Profit")

    else:
        print(Loss(costPrice,
                   sellingPrice), "Loss")

The error code:

Traceback (most recent call last):   File "C:/Users/sharv/PycharmProjects/FInal Robotic/Finals.py", line 18, in <module>
    input(costPrice, sellingPrice) NameError: name 'costPrice' is not defined

Process finished with exit code 1
quamrana
  • 37,849
  • 12
  • 53
  • 71
Ecstashar
  • 31
  • 6
  • Please update your question with the full error traceback. – quamrana Dec 07 '20 at 17:34
  • Between the confusion with `input` and the awkward local variables in the functions, my guess is that whatever Python tutorial you're following was written by a BASIC programmer who concluded that Python is "basically the same thing" as the language she knows. I might recommend looking for a different tutorial. – Silvio Mayolo Dec 07 '20 at 17:38
  • Old question, but the first answer has Python 2 and 3 solutions: [Two values from one input in python?](https://stackoverflow.com/questions/961263/two-values-from-one-input-in-python) – bbnumber2 Dec 07 '20 at 17:40

2 Answers2

2

If you would like to input 2 values from the user, you will have to do it like that:

cost_price = input("Enter Cost Price: ")
sell_price = input("Enter Selling Price: ")

The input function in python takes as argument a string text to display to the user (An optional argument) and returns the inputed value from the user (as a str object). If you would like to convert those values into numbers, you will have to do something like:

# integer values
cost_price = int(input("Enter Cost Price: "))
sell_price = int(input("Enter Selling Price: "))

# OR:

# Floating point values
cost_price = float(input("Enter Cost Price: "))
sell_price = float(input("Enter Selling Price: "))
Or Y
  • 2,088
  • 3
  • 16
1
input(costPrice, sellingPrice)

Whoever told you input takes output variables as arguments is mistaken. If you want to input into the two variables, you'll do so as follows

costPrice = input()
sellingPrice = input()

You'll also likely want to convert them to numbers.

costPrice = float(input())
sellingPrice = float(input())
Silvio Mayolo
  • 62,821
  • 6
  • 74
  • 116