1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Jet001 [13]
3 years ago
12

python A pet shop wants to give a discount to its clients if they buy one or more pets. The discount is equal to 20 percent of t

he cost of the other items, but not the pets. Implement a function def discount(prices, isPet, nItems) The function receives information about a particular sale. For the ith item, prices[i] is the price before any discount, and isPet[i] is true if the item is a pet. Write a program that prompts a cashier to enter each price and then a Y for a pet or N for another item. Use a price of –1 as a sentinel. Save the inputs in a list. Call the function that you implemented, and display the discount.
Computers and Technology
1 answer:
Artyom0805 [142]3 years ago
8 0

Answer:

The following are the program in the Python Programming Language.

#define function

def discount(prices, isPet, nItems):

 # declare and initialize variables to 0

 i = 0

 cost = 0

 pets = 0

 item = 0

 item_Cost = 0

 #set the while loop

 while(i < nItems):

   #check the items of the variable

   if isPet[i]:

     #add and initialize in the cost

     cost += prices[i]

     #increament in the variable by 1

     pets += 1

   #otherwise

   else:

     #add and initialize in the item_Cost

     item_Cost += prices[i]

     #increament in the variable by 1

     item += 1

   #then increment in the variable by 1

   i += 1

 #check the pet is greater than equal to 1  

 #and item is greater than equal to 5

 if(pets >= 1 and item >=5):

   #then, print the message

   print("You receive discount")

   #set discount of the items

   discount = 0.2 * item_Cost

   # calculate bill after deducting discount

   bill = cost + item_Cost - discount

   #print the bill

   print("Final Bill amount is", bill)

 #otherwise

 else:

   #print the message

   print("You do not receive any discount")

   #calculate bill without deducting discount

   bill = cost + item_Cost

   #print the final bill

   print("Final Bill amount is", bill)

#set empty list type variables

price = []

pet = []

#set the infinite loop

while True:

 #get input from the user

 sprice = int(input("Enter the price (-1 to quit): "))

 #check that price is not equal to the -1

 if(sprice != -1):

   #add price in the list

   price.append(sprice)

   #ask for choice from the user

   choice = input("Is it a pet (Y / N)? ")

   #check the choice of the user is y or Y

   if(choice == 'Y' or choice == 'y'):

     # then, add in the pet

     pet.append(True)

   #otherwise

   else:

     #not add in the pet

     pet.append(False)

   print("")

 #break the loop

 else:

   break

#declare variable that store the length

items = len(price)

#call and initialize the variable

discount(price, pet, items)

<u>Output</u>:

Enter the price (-1 to quit): 96

Is it a pet (Y / N)? y

Enter the price (-1 to quit): 69

Is it a pet (Y / N)? n

Enter the price (-1 to quit): 41

Is it a pet (Y / N)? n

Enter the price (-1 to quit): 52

Is it a pet (Y / N)? n

Enter the price (-1 to quit): 96

Is it a pet (Y / N)? n

Enter the price (-1 to quit): 74

Is it a pet (Y / N)? n

Enter the price (-1 to quit): -1

You receive discount

Final Bill amount is 361.6

Explanation:

<u>The following are the description of the program</u>.

  • Firstly, define the function 'discount()' and pass the arguments 'prices', 'isPet' and 'nItems' in its parameter.
  • Then, declare and initialize the variables 'i' to 0, 'item_Cost' to 0
  • , item to 0, 'cost' to 0 and 'pets' to 0.
  • Then, set the while loop to add the price of the items and the cost of the pets.
  • Set the if-else conditional statement to check the pet is greater than equal to 1 and the items are greater than equal to 5 then, set the discount and print the bill after deduction.
  • Otherwise, print the bill without deduction.
  • Finally, set two list type variable then, set the infinite while loop that gets input from the user and check that the variable is not equal to -1 then append the data in the list then again check the user input then append in pet otherwise not append in pet and break the loop. Then, set the variable that stores the length of the price and call the following function by passing arguments in its parameter.
You might be interested in
Which of the following cannot be created using Word software?
Arturiano [62]
3-database of new clients
7 0
3 years ago
PA theme is a major message that a writer convoys through a text. you have explored many themes in the hobbit one theme in the n
Nataly [62]

Answer:

The Hobbit’s main theme is Bilbo’s development into a hero, which more broadly represents the development of a common person into a hero. At the beginning of the story, Bilbo is timid, comfortable, and complacent in his secure little hole at Bag End. When Gandalf talks him into embarking on the quest with Thorin’s dwarves, Bilbo becomes so frightened that he faints. But as the novel progresses, Bilbo prevails in the face of danger and adversity, justifying Gandalf’s early claim that there is more to the little hobbit than meets the eye.??????

Explanation:

7 0
2 years ago
What is the output of this program?
Charra [1.4K]

Answer:

20

Explanation:

assuming the print statement is not indented, the program effectively calculates 2+5+6+7.

The range(...) is <em>excluding </em>the end value (8 in this case).

3 0
2 years ago
Read 2 more answers
Select the correct answer.
andriy [413]

Answer:

C. Rulers indicate the margins, tabs, and indents in a presentation slide.

Explanation:

The status bar appears at the bottom of the page, and it never displays options the options to style the slides. And the toolbar never displays the thumbnails of the slides, as well as the document area never provides a list of the commands for creating, formatting or editing the presentations. However, the rules do indicates the margins, tabs, and indents in a presentation slide. Hence C. is the right option.

8 0
3 years ago
If you create an object using Java’s BigDecimal class, and then perform a division that results in a non-terminating decimal div
azamat

Answer:

Arithmetic Exception is the correct answer to the following blank.

Explanation:

Because the BigDecimal class is the class of the Java Programming Language that deal with the double data type numbers for the arithmetic expressions and also for the format conversions and it is the math type class of the Java Programming language which is used in arithmetic operations. So, that's why the following answer is not wrong.

3 0
3 years ago
Other questions:
  • Consider two sets S1 and S2 of size 3 and 2 each.
    13·1 answer
  • Which devices typically generate computer output ?
    8·2 answers
  • 1. What makes discrimination different from harassment? (Don't give me definitions.)
    5·1 answer
  • Como hago para poner brainly en español???
    12·2 answers
  • I.d 9934607467<br> p.a.s.s 54321<br><br> P.L.E.A.S.E J.O.I.N. Z.O.0.M. M.E.E.T.I.N.G
    10·1 answer
  • Problem: Mr. James Reid, the director of admissions at MOGCHS University, has
    14·1 answer
  • 9. Select the correct answer.
    6·1 answer
  • Which of the following screen elements is a horizontal bar that displays at the
    8·1 answer
  • What keyword is used in Java to create a parent/child relationship between two classes?
    14·1 answer
  • Create a list of 5 potential jobs that students of computer science can obtain.
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!