0
#Get the user's name.
Name = input('Enter your name.')

#Get number of stocks purchased.
Stocks_P = int(input('Enter the number of stocks purchased.'))

#Get purchase price of stocks.
Price_P = float(input('Enter the price of stocks purchased.'))

#Calculate total price.
Total_price = Stocks_P * Price_P

#Calculate Commission.
Com1 = Total_price * 0.03

#Calculate Cost.
Cost = Com1 + Total_price

#Get number of stocks sold.
Stocks_S = int(input('Enter the number of stocks sold.'))

#Get sale price of stocks.
Price_S = float(input('Enter the sale price of stocks.'))

#Calculate sale.
Sale = Stocks_S * Price_S

#Calculate sale Commission.
Com2 = Sale * 0.03

#Calculate profit or loss.
Profit = Sale - (Cost + Com2)

print('Your end total is: $' format(Profit, ',.2f') Name, sep='')

that's what i'm using for my first assignment in my python class, and in the last line, anything after the "print('You end total is: $' returns a syntax error no matter how i change it.

2
  • You're missing commas (and/or using format in a really weird way). Commented Sep 29, 2015 at 14:25
  • What were you expecting a output from print('Your end total is: $' format(Profit, ',.2f') Name, sep='') ? Commented Sep 29, 2015 at 14:25

1 Answer 1

3

Indeed, just listing a string, a format() call and a variable name in a row is not valid Python syntax.

Either pass those three things in as separate arguments, using commas, or create a str.format() template for the values to be interpolated into:

print('Your end total is: $', format(Profit, ',.2f'), Name, sep='')

or

print('Your end total is: ${:,.2f}{}'.format(Profit, Name))
Sign up to request clarification or add additional context in comments.

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.