In: Computer Science
PYTHON: This is the posted problem:
General Instructions
Create a function called DeterminePrice that will determine the cost of purchased software. The price is of the software is $350 per license. However, when purchased in larger quantities a discount is given. For quantites less than 10 copies, there is no discount. For quantities greater than 10 and less than and including 20, a 10% discount is given. For quantities greater than 20 and less than and including 30, a discount of 20% is given. For quantities greater than 30 and less than and including 40, a discount of 30% is given. Finally if someone needs to purchase more than 40 copies, a discount of 40% is given.
Your function needs to take in to it the number of quantities the user wishes to purchase. It needs to return back to main() the discount given and the total cost of the software purchase.
Output and Testing
MyProgramming Lab will call your function. Therefore, you MUST make sure you name your function DeterminePrice(). Otherwise MyProgramming lab will not be able to locate your function. Additionally when you write function make sure it first returns discount and then total. Otherwise your discount and total will not print out correctly.
When your function is run, the output from the first test will look like the following:
Enter the number of copies: 35
Discount: $ 105.00
Total: $ 8,575.00
This is my code, which runs in Python, but not MPL, which uses a Linux server to process problems:
n=int()
d=float()
total=float()
def main():
def get_num_of_copies():
n = int(input("Enter the number of copies: "))
return n
n = get_num_of_copies()
def discount():
if n <= 9:
d = 0
elif n >=10 and n <= 20:
d = .1
elif n >=21 and n <=30:
d = .2
elif n >=31 and n <=40:
d = .3
elif n >40:
d = .4
return d
d = discount()
def DeterminePrice():
total = ( (n*350) - ((n*350) * d) )
return total
total = DeterminePrice()
print ("Discount:\t$",format((350 * d),',.2f'))
print ("Total:\t\t$",format((total),',.2f'))
main()
So I asked the teacher for help. She said that I need to move I need to move my functions out of main (def discount, for example). I can't do that without getting "indentation" errors from Python.
These are the error messages I am getting from MPL:
⇒ Traceback
(most recent call last):
⇒ File
"main.py", line 90, in
⇒ main()
⇒ File
"main.py", line 51, in main
⇒ user_quantity
= int(input("Enter the number of copies: "))
⇒ EOFError:
EOF when reading a line
I edited your code, there is no need for a main function:
n=int()
d=float()
total=float()
def get_num_of_copies():
n = int(input("Enter the number of copies: "))
return n
n = get_num_of_copies()
def discount():
if n <= 9:
d = 0
elif n >=10 and n <= 20:
d = .1
elif n >=21 and n <=30:
d = .2
elif n >=31 and n <=40:
d = .3
elif n >40:
d = .4
return d
d = discount()
def DeterminePrice():
total = ( (n*350) - ((n*350) * d) )
return total
total = DeterminePrice()
print ("Discount:\t$",format((350 * d),',.2f'))
print ("Total:\t\t$",format((total),',.2f'))
This works on linux without errors
thank you, please upvote.