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]
2 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]2 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
Please respond not with answer but with comment.
aksik [14]

Answer:.I used to play it but now I don’t;—;

Explanation:

4 0
2 years ago
7) Which of the following factors determines the structure, features, and functions of an information system used in a company?
elena-s [515]

Answer:

The correct option is A: Competitive Strategy

Explanation:

The competitive strategy of an organization is the factor that determines the function, feature and structure of the information system that will be used. The value of its brand has nothing to do with the form of info system to be used, neither is the size of the company a determinant factor of the information system to be used. You cannot determine your own information system structure and function by that of a competitor. Hence the correct option is A. In every organization, the information system has great impact on competitive advantage in differentiation or cost.

5 0
3 years ago
Write a program that uses two input statements to get two words as input. Then, print the words on one line separated by a space
Shkiper50 [21]

word1 = input("Enter a word: ")

word2 = input("Enter a word: ")

print(word1 + " " + word2)

I hope this helps!

6 0
2 years ago
Why procedures are used and what must be the lastexecutable instruction in a<br><br> procedure?
Art [367]

Answer:

Procedure are used to create and modifying the programs. Basically, it is grouping of instruction that can be used give direction of the flow of program. Control are given to the next term once the execution of the instruction get over. The steps of procedure are:

procedure are first executed the declaration instruction and then coding the procedure, then it will return to the directories and the last executable instruction is the termination of procedure.

4 0
2 years ago
12.
natali 33 [55]

Answer:

The answer is "Its fundamental economic structure of IP, which is based on the concept of incentives".

Explanation:

In the given question the correct choice is missing so, its solution can be defined as follows:

It is a copyrighted category that includes subjective human mind works. which exists in different forms, and also some countries recognize much more than others. Copyright laws, patents, trade secrets, and trademarks are the most famous types.  

  • This is a law that promotes the creation of a broad range of intellectual goods.
  • To do just that, the law gives the information and creative goods made, generally for a limited time, rights to individuals and companies.
7 0
3 years ago
Other questions:
  • Which Of The Following Is A College Major For Which IT Courses Would Most Likely Be Required?
    9·1 answer
  • True false you cannot fill in a callout​
    14·1 answer
  • Whenever Jim starts his laptop, he sees some commands and numbers appearing on his screen. These instructions are being processe
    12·2 answers
  • Please help me answer this question
    14·1 answer
  • How do u use this app?
    15·2 answers
  • How come I haven't moved to the next rank even though I have all of the right things to move on?
    10·2 answers
  • What should be used to keep a tablet dry?
    13·1 answer
  • Is iphone battery being draned if plugged into car charger when listening to podcasts
    6·1 answer
  • What features should you present when demonstrating 2023 murano’s confident cornering?.
    11·1 answer
  • Why are salaried employees often excluded from overtime pay
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!