I am writing a program to determine a car salesman profit for a new or pre-owned vehicle.
I need to express all three outputs in currency format with the $ sign right up against the first digit and two decimal places.
I need to add commas for any profit earned over $1000.
The salesman gets 25% profit from a pre-owned sale and 35% profit from new sales.
Pseudocode
Start Program
The salesperson gets 25% dealer profit on pre-owned vehicles.
The salesperson gets 35% dealer profit
Enter the total dealer profit on pre-owned vehicles sold.
Enter total dealer profit on new vehicles sold.
The input type should float.
Compute and display commission amounts
Compute and display the total commission.
Print out the sum.
End Program
Code so far
def main():
pre-owned_vehicles = float(input("Enter total profit on pre-owned vehicles sold * 0.25: "))
new_vehicles = float(input("Enter total profit on new vehicles sold * 0.35: "))
commission pre-owned sales = float(input("Enter commission pre_owned: "))
commission new sales = float(input("Enter commission new: "))
total = profit + commission
print('Pre-owned sales profit is $')
format(new sale profit, ',.2f)
main()
You are getting a SyntaxError because you cannot have variable names with hyphens (or spaces) in between, it thinks you are trying to subtract. Thus, change your code to:
pre-owned_vehicles = float(input("Enter total profit on pre-owned vehicles sold * 0.25: "))
And carry on.
>>> foo-bar = 'foo-bar'
File "<stdin>", line 1
SyntaxError: can't assign to operator
>>> foo_bar = 'foo-bar'
>>>
Related
I want to implement a function to calculate mortgages. It takes the user input such as the loan amount, duration of the loan, the frequency of payment in a year, and the annualized interest rate. After the necessary input, the function will generate an output to show the user the total interest needed to pay after the end of the period of the loan, and the total amount to pay (total loan interest + loan amount).
This is what I have done:
def get_mortgage_cashflows():
loan_amount = float(input('Enter mortgage loan amount: '))
loan_period = float(input('Enter the number of period in years: '))
loan_frequency = int(input('Enter the number of payment per year: '))
loan_interest = float(input('Enter the annual interest rate: '))
loan_total_interest = (loan_amount * (1 + (loan_interest / 100) / loan_frequency) ** loan_period) - loan_amount
loan_total_amount = loan_amount + loan_total_interest
return loan_total_interest, loan_total_amount
total_interest, total_amount = get_mortgage_cashflows()
print('total interest: ', total_interest)
print('total payment amount: ', total_amount)
However, there seems to be an error as there is no output generated.
A sample test case from my class activities:
Mortgage loan: $1,000,000
Period: 10 years
Frequency: Annual repayment
Annualized interest rate: 1.5%
Any assistance is appreciated!
Using your code, I get:
Enter mortgage loan amount: >? 1000000
Enter the number of period in years: >? 10
Enter the number of payment per year: >? 1
Enter the annual interest rate: >? 1.5
total interest: 160540.82502514892
total payment amount: 1160540.825025149
Can you try again to run the code you gave us and confirm you still have the issue ?
Here's the code:
P = int(input("Enter starting principle please.\n"))
n = int(input("Enter Compound interest rate.(daily, monthly, quarterly,half-year, yearly)\n"))
r = float(input("Enter annual interest amount. (decimal)\n"))
t = int(input("Enter the amount of years.\n"))
t = 1
while t-1 <= 5-1 :
final = P * (((1 + (r/n)) ** (n*t)))
t += 1
print ("The final amount after", round(t-1), "years is", round(final,2))
When I tried to input:
1000
1
0.02
2
it will result like this:
Enter starting principle please.
Enter Compound interest rate.(daily, monthly, quarterly, half-year, yearly)
Enter annual interest amount. (decimal)
Enter the amount of years.
The final amount after 1 years is 1020.0
The final amount after 2 years is 1040.4
The final amount after 3 years is 1061.21
The final amount after 4 years is 1082.43
The final amount after 5 years is 1104.08
The problem is, it will not return to the require input number of years (e.g when I tried to input 2 years it will print up to 5 years)
Why are you setting t from input, but then immediately ignoring the input and overwriting its value with t = 1?
And where is this 5 coming from: while t-1 <= 5-1
Essentially you need a new variable for what you're doing in the loop, separate from t. And "magic numbers" like 5 appearing in code for no reason are something to be avoided.
P = int(input("Enter starting principle please.\n"))
n = int(input("Enter Compound interest rate.(daily, monthly, quarterly, half-year, yearly)\n"))
r = float(input("Enter annual interest amount. (decimal)\n"))
t = int(input("Enter the amount of years.\n"))
for t in range(1, t+1):
final = P * (((1 + (r/n)) ** (n*t)))
t += 1
print ("The final amount after", round(t-1), "years is", round(final,2))
I'm given gm%, gm&, sales, sales cost, and several of the same dates. For every date, I want to find the total Gross Margin Percentage for that day. How can I do that in Excel? I want my output to list a unique date and the GM% corresponding to the date.
You can't average gross margin percentages and get an accurate figure. You need the total cost and total retail (/selling price) amounts, and with the total cost and retail amounts you'll be able to calculate the average gross margin percentage with 1-Sum([Cost])/Sum([Retail]).
Averaging percentages is not accurate reporting. Proof:
Units Cost Retail GM%
10 379 1000 62.1%
1 327 650 49.7%
The "average" GM% you would be aggregating would be 55.9%...
but the correct GM% would be 57.2%.
If all you have is the total sales amount and the GM%, you need to compute the total cost:
[Cost$] = [GM%]*[Retail$]
If all you have is the total cost amount and the GM%, you need to compute the total retail:
[Retail$] = [Cost$]/(1-[GM%])
If you have the GM$ amount and the GM%, you can calculate both cost and retail amounts:
[GM%] = [GM$]/[Retail$]
[GM$] = [Retail$]-[Cost$]
[Retail$] = 1/[GM%]*[GM$]
[Cost$] = 1/[GM%]*[GM$]*(1-[GM%])
With these, you can now accurately compute the average GM% figure.
I want to make a function in excel program to calculate multiple taxes.
x=main salary = 30000 as an example.
then >>
I divide the x into 10000s
the first 10000 in x has no tax,
the second 10000 in x has 10% as tax,
more than that has 15% as tax
I need
main salary - taxes = real salary.
The Formula for the Tax is:
=IF(A1-10000>0,IF(A1-20000>0,(A1-20000)*15%+(10000*10%),(A1-10000)*10%),0)
A1 the initial salary
In case the salary is <= 10000 no Tax it returns 0
If will test
In case A1-20000 >0 True will apply 15% on A1-20000 + 10000*10%
In case A1-20000 <=0 10% will be applied to A1-10000
The result will be the Total Taxes
I have been working on a program for my homework:
Write a program for a car salesperson who works a five day week. The program should prompt for how many cars were sold on each day and then prompt for the selling price of each car (if any) on that day. After the data for all five days have been entered, the program should report the total number of cars sold and the total sales for the period. See example output. NOTE: duplicate the currency format shown for the total sales,
Example Output
How many cars were sold on day 1? 1
Selling price of car 1? 30000
How many cars were sold on day 2? 2
Selling price of car 1? 35000
Selling price of car 2? 45000
How many cars were sold on day 3? 0
How many cars were sold on day 4? 1
Selling price of car 1? 30000
How many cars were sold on day 5? 0
You sold 4 cars for total sales of $140,000.00
I do have some code that I have worked on but I am stuck. I can figure out how to get the program to prompt the user for how many cars were sold on day 2 and so on. Any help would be appreciated!
Here is my code, I am also taking a basic python course so I am new to this!!
def main () :
cars_sold = []
num_days = int(input('How many days do you have sales?'))
for count in range(1, num_days + 1):
cars = int(input('How many cars were sold on day?' + \
str(count) + ' '))
while (cars != cars_sold):
for count in range(1, cars + 1):
cars_sold = int(input('Selling price of car' ' ' + \
str(count) + ' '))
main ()
For this you would want to use nested for loop to prompt for each car entered.
def main():
cars_sold = 0
total = 0
num_days = int(input('How many days do you have sales? '))
# for each day
for i in range(1, num_days + 1):
num_cars = int(input('How many cars were sold on day {0}? '.format(i)))
cars_sold += num_cars
# for each car of each day
for j in range(1, num_cars + 1):
price = int(input('Selling price of car {0}? '.format(j)))
total += price
# Output number of cars and total sales with $ and comma format to 2 decimal places
print('You sold {0} cars for total sales of ${1:,.2f}'.format(cars_sold, total))
# Output
>>> main()
How many days do you have sales? 5
How many cars were sold on day 1? 1
Selling price of car 1? 30000
How many cars were sold on day 2? 2
Selling price of car 1? 35000
Selling price of car 2? 45000
How many cars were sold on day 3? 0
How many cars were sold on day 4? 1
Selling price of car 1? 30000
How many cars were sold on day 5? 0
You sold 4 cars for total sales of $140,000.00