Question

In: Computer Science

PYTHON: This is the posted problem: General Instructions Create a function called DeterminePrice that will determine...

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

Solutions

Expert Solution

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.


Related Solutions

In Python Create a function called ℎ?????. The function has as arguments a list called ??????...
In Python Create a function called ℎ?????. The function has as arguments a list called ?????? and a list call center. • List ?????? contains lists that represent points. o For example, if ?????? = [[4,2], [3,2], [6,1]], the list [4,2] represents the point with coordinate ? at 4 and y coordinate at 2, and so on for the other lists. Assume that all lists within points contain two numbers (that is, they have x, y coordinates). • List ??????...
The programming language is Python Instructions: Create a function that will delete a node in a...
The programming language is Python Instructions: Create a function that will delete a node in a Linked List based on position number. On below example, if you want to delete position #2, it will remove the Banana (arrangement of nodes below is Apple, Banana, Cherry, Grapes, Orange). myLinkedList = LinkedList() myLinkedList.append("Banana") myLinkedList.append("Cherry") myLinkedList.append("Grapes") myLinkedList.append("Orange") myLinkedList.prepend("Apple") myLinkedList.deleteByPositionNum(2) node = myLinkedList.head while node: print(node.value, " ") node = node.next_node You may start with the function head: def deleteByPositionNum(self, positionNum):
In Python Create a function called ????. The function receives a "string" that represents a year...
In Python Create a function called ????. The function receives a "string" that represents a year (the variable with this "String" will be called uve) and a list containing "strings" representing bank accounts (call this list ????). • Each account is represented by 8 characters. The format of each account number is "** - ** - **", where the asterisks are replaced by numeric characters. o For example, “59-04-23”. • The two central characters of the "string" of each account...
IN PYTHON Create a function called biochild.  The function has as parameters the number m...
IN PYTHON Create a function called biochild.  The function has as parameters the number m and the lists biomother and biofather.  The biomother and biofather lists contain 0’s and 1’s.  For example: biomother = [1,0,0,1,0,1] and biofather = [1,1,1,0,0,1]  Both lists have the same length n.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child).  The child...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
Python pls create a function called search_position. This function returns a list. team1 = {'Fiora': {'Top':...
Python pls create a function called search_position. This function returns a list. team1 = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3},'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4},'Yasuo': {'Mid': 2, 'Top': 5},'Shaco': {'Jungle': 4, 'Top': 2, 'Mid': 1}} def search_position(team1): returns [(5, [('Top', ['Yasuo'])]), (4, [('Mid', ['Fiora']), ('Support',['Olaf']), ('Jungle',['Shaco'])])   (3, [('Bottom', ['Fiora']), ('Top', ['Olaf'])]), (2, [('Mid', ['Olaf','Yasuo']), ('Top', ['Shaco'])]), (1, [('Mid', ['Shaco'])])]
Python pls create a function called search_position. This function returns a dictionary. team1 = {'Fiora': {'Top':...
Python pls create a function called search_position. This function returns a dictionary. team1 = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3},'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4},'Yasuo': {'Mid': 2, 'Top': 5},'Shaco': {'Jungle': 4, 'Top': 2, 'Mid': 1}} def search_position(team1): should return {'Top': {'Fiora': 1, 'Yasuo':5,'Olaf':3,'Shaco':}, 'Jungle': {'Shaco': 4}, 'Mid': {'Yasuo', 2, 'Fiora': 4,'Olaf':2}, 'Bottom': {'Fiora': 3}, 'Support': {'Olaf': 4}} *******IMPORTANT*************** The result should be alphabetical order.
Python Create a move function that is only defined in the base class called Objects. The...
Python Create a move function that is only defined in the base class called Objects. The move function will take two parameters x,y and will also return the updated x,y parameters.
In python please write the following code the problem. Write a function called play_round that simulates...
In python please write the following code the problem. Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the case of a tie, draw more cards. Repeat until someone wins the round. The function has two parameters: the name of player 1 and the name of player 2. It returns a string with format '<winning player name> wins!'. For instance, if the winning player is named Rocket, return 'Rocket wins!'.
THANK YOU FOR ANSWERING THE 4 QUESTIONS Q3. Create a function in Python called sum_list_div2 which...
THANK YOU FOR ANSWERING THE 4 QUESTIONS Q3. Create a function in Python called sum_list_div2 which takes as input a list of integers and returns the sum of the elements of the list which divide by 2. Examples of tests in the Python interpreter: >>> sum_list_div2 ([1,4,3,8,5]) 12 >>> sum_list_div2 ([]) 0 >>> sum_list_div2 ([4, -10,7]) -6 -------------------------------------------------------------------------------------------------------------------------------------------------------------- Q5. Imagine a customer at a bank who must enter a number that represents their money. There are people who type spaces...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT