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
astraxan [27]
2 years ago
12

Write a program that keeps track of a simple inventory for a store. While there are still items left in the inventory, ask the u

ser how many items they would like to buy. Then print out how many are left in inventory after the purchase. You should use a while loop for this problem. A sample run is below.
(CodeHS, PYTHON)
Computers and Technology
2 answers:
neonofarm [45]2 years ago
4 0

Answer:

STARTING_ITEMS_IN_INVENTORY = 20

num_items = STARTING_ITEMS_IN_INVENTORY

# Enter your code here

while num_items > 0:

print("We have " + str(num_items) + " items in inventory")

toBuy = int(input("How many would you like to buy?"))

if toBuy > num_items:

print("There is not enough in inventory")

print("Now we have " + str(num_items) + " left")

else: # ok to sell

num_items = num_items - toBuy # update

if num_items > 0: # only for printing

print("Now we have " + str(num_items) + " left")

print("All out!")

Explanation:

This allows Python to store the number of items in inventory after each purchase by subtracting how much is bought with the toBuy function by how much is left. This continues until num_items is no longer greater than zero. If what’s toBuy goes above the # of items left in inventory, then the “if toBuy > num_items” segment of the code comes into play by telling the user there’s not enough and re telling them how much is left and how much they’d like to buy. When the items in inventory is out, meaning the exact amount that’s left is purchased, then Python prints “All out!”

MissTica2 years ago
3 0

Answer:no

Explanation:

You might be interested in
6. Which of the following is malware? (1 point)
marusya05 [52]
Software to damage computers
5 0
3 years ago
Read 2 more answers
The Speed of Sound (Java Project. Please make it easy to understand. I'm a beginner at this. I believe we are supposed to use a
Ilya [14]

Answer:

The program of this question can be given as:

Program:

//import pacakge for user input.

import java.util.Scanner;

//define class  

public class SpeedofSound              

{

  public static void main(String a[]) //define main function

  {  

      //define variable.

      String medium;                            

      double distance,time=0;

      //creating Scanner class object for input from user.

      Scanner s=new Scanner(System.in);  

      //print message.

      System.out.printf("Enter medium(air,water or steel) : ");

      medium=s.nextLine();  //taking input.

      //print message.

      System.out.printf("Enter the distance that the sound will travel : ");

      distance=s.nextDouble(); //taking input.

      switch(medium) //checking condtion between range.

      {

          case "air":

                  time=distance/1100;         //apply formula

                  break;

          case "water":

                  time=distance/4900;            //apply formula

                  break;

          case "steel":

                  time=distance/16400;            //apply formula

                  break;

          default:

                  System.out.printf("Sorry, you must enter air,water or steel"); //error for invalid input of medium

                  System.exit(0);

      }

      System.out.printf("It take "+time+" seconds"); //print final answer.

  }

}

Output:

Enter medium(air,water or steel) : air

Enter the distance that the sound will travel : 200

It take 0.18181818181818182 seconds

Explanation:

In this program first, we import packages for user input. Then we declare the class in the class we declare all the variables and then we create the scanner class object. It is used for taking input from the user. Then we use the switch statement It is used for condition. It works between the ranges. In the switch statement, we apply all the formula that is given in the question. and at the last, we print the output using printf function in java.

6 0
3 years ago
Three periods after a menu item (...) mean that clicking that command will open
erastovalidia [21]

I think its B.) A dialog box


7 0
3 years ago
Read 2 more answers
Consider the following methods:
elena55 [62]
3. 8.1  
Looking at the functions "average", and "mystery" it's pretty obvious that "average" returns a double precision average of the value of an integer array. The function "mystery" returns an array of integers with each value in the array being the length of the string in the array of strings passed to "mystery" in the same ordinal position.  
The main body of the code initializes an array of strings and then passes that array to "mystery" who's output is then passed into the function "average". Since the lengths of the words passed to "mystery" is 7, 5, 6, 10, 10, 8, 13, 6, 8, 8, the sum will be 81, so the average will be 81/10 = 8.1 which matches option "3".
4 0
3 years ago
Suppose you wanted to run a web server or ftp server from your home. what type of ip address would you want?​
Greeley [361]
You would need to have a static ip address.
3 0
2 years ago
Other questions:
  • A(n) _____ is a simple database program whose records have no relationship to one another.
    10·1 answer
  • .) Write a complete C program in one file which takes a double value from the user, cubes it, and prints the result. Your progra
    10·1 answer
  • What is software that, while purporting to serve some useful function and often fulfilling that function, also allows Internet a
    11·1 answer
  • with the _______ network topology, reliability is the major advantage while high cost is the disadvantage.
    10·2 answers
  • _______ is a form of crime that targets a computer system to acquire information stored on that computer system, to control the
    15·1 answer
  • The scheme function (mult2-diff Ist) should take one argument, a list of numbers, and results in multiplying each number in the
    11·1 answer
  • When sketching out your Web site you create a clear and straightforward site map that divides the Web site content into a logica
    9·1 answer
  • The output for the following code will be: Pasta (1 mark)
    6·1 answer
  • A student is browsing a website. While browsing, he click on a link that takes him to another website. Which code gives the corr
    14·1 answer
  • The equals method of the Object class returns true only if the two objects being compared:_________
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!