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
emmainna [20.7K]
3 years ago
11

Write a program that declares and initializes a variable representing the weight in milligrams from the keyboard. The program di

splays the equivalent weight in kilograms, grams, and milligrams. For example, 1050042 milligrams are equivalent to 1 kilogram, 50 grams, and 42 milligrams.
Computers and Technology
1 answer:
Burka [1]3 years ago
3 0

Answer:

weight = int(input("Enter weight in milligrams: "))

kilograms = int(weight / 1000000)

grams = int((weight - (kilograms * 1000000)) / 1000)

milligrams = weight - ((kilograms * 1000000) + (grams * 1000))

print("{} milligrams are equivalent to {} kilogram(s), {} gram(s), and {} milligram(s)".format(weight, kilograms, grams, milligrams))

Explanation:

*The code is in Python.

Ask the user to enter the weight and set it to the variable weight

Calculate the kilograms, divide the weight by 1000000 and cast the result to the int (If the weight is 1050042, kilograms would be 1050042/1000000 = 1)

Calculate the grams, subtract the kilograms from the weight, divide it by 1000 and cast the result to the int (If the weight is 1050042, grams would be int((1050042 - (1 * 1000000)) / 1000) = 50)

Calculate the milligrams, subtract the kilograms and grams from the weight (If the weight is 1050042, milligrams would be 1050042 - ((1 * 1000000) + (50 * 1000)) = 42)

Print the weight, kilograms, grams, and milligrams in the required format

You might be interested in
What happens when there is a data fail?
Korvikt [17]
Data loss also sets back productivity timelines and can cause you to lose customers if it is accompanied by security breaches
7 0
3 years ago
Read 2 more answers
In which of the following mouse operations do you move the mouse until the pointer is positioned on the item of choice?
wolverine [178]
It's a. You have to move to the item thus pointing ;D
8 0
3 years ago
A "flat file" is also called
Colt1911 [192]
I think it would be
Unstructured file
5 0
4 years ago
Complete the sentence to identify advantages of top-down programming design. Choose all that apply.
yanalaym [24]

Answer:The original choice to write apply_fg so that it accepts function arguments is a good one, because it increases interoperability. When the callable arguments to apply_fg use a single protocol, we can easily exchange them: #include <functional> float log2(float); int a = apply_fg(5.Of, int b = apply_fg(3.14f,

Explanation:

3 0
4 years ago
Read 2 more answers
Which device makes computers that are connected to separate segments appear and behave as if they're on the same segment? (Pleas
Mashcka [7]

Answer: Switch

Explanation:

 The switch is the device that is basically use for the connection for separate segment that basically appear in the similar segment in the computer network.

Switch is the ethernet that is based on the  LAN peruses approaching TCP/IP information packets containing goal data as they go into at least one info ports. The goal data in the bundles is utilized to figure out which yield ports that will be utilized to sending the information on to its proposed goal.

Therefore, Switch is the correct options.

 

4 0
4 years ago
Other questions:
  • When a vehicle strikes a pedestrian, it's most often during A. a period of darkness or low visibility B. the day when pedestrian
    10·2 answers
  • Processing is handled by the computer’s central processing unit (cpu).​ <br> a. True <br> b. False
    6·1 answer
  • This LEGENDARY character made a much-celebrated comeback in 2017. What was the name of the villain he faced in this epic tale?
    7·2 answers
  • What type of hardward drive not require defragging??
    11·1 answer
  • Discuss and compare shared and switch Ethernet
    12·1 answer
  • You are asked to add speech to a robotic receptionist that sits at the front desk of a large organization. The robot has an anim
    10·2 answers
  • Which of the following best describes the protocol used on the internet?
    8·1 answer
  • a term to describe article that can be displayed in their entirety as opposed to abstract and reference only?​
    10·1 answer
  • PLEASE HELLPPPPP EVERYONE IS IGNORING THISSSSSSSSSS
    11·1 answer
  • What is operating system​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!