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'])])]
In python please Problem Create two server objects using the class create a function, biggest_server_object_sum, outside...
In python please Problem Create two server objects using the class create a function, biggest_server_object_sum, outside of the ServerClass class, that: 1. Takes the IP 2. Sums the octets of the IP together (example 127.0.0.1 = 127+0+0+1 = 128) 3. Returns the Server object with the larger sum Example: server_one = ServerClass("127.0.0.1") server_two = ServerClass("192.168.0.1") result = biggest_ip_sum(server_one, server_two) print(result) Hint Modify get_server_ip in the previous problem. -------------------- Please use this code to start class ServerClass: """ Server class for...
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!'.
In python i want to create a function. The function will take in two linked lists...
In python i want to create a function. The function will take in two linked lists as the parameters. If one is shorter than the other then the shorter will be the length. I want to take the values from both linked lists and turn them into tuples. I then want these tuples to be put into a new linked list. I want to return that linked list. I want to do this using recursion and no helper functions or...
In python of Jupiter notebook Write a python function called trng that takes three numbers x,...
In python of Jupiter notebook Write a python function called trng that takes three numbers x, y, and z, and specifies if those can form a triangle (i.e., returns the word triangle if they can, and Not a triangleotherwise). Note: In order for three numbers to form a triangle sum of any two of them must be greater than the third one (e.g., x=1, y=2, z=4 cannot form a triangle because x+y is not greater than z even though x+z>y...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT