Reputation: 29
#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.
Upvotes: 0
Views: 5345
Reputation: 1121486
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))
Upvotes: 3