Welcome to Westonci.ca, where finding answers to your questions is made simple by our community of experts. Join our platform to connect with experts ready to provide precise answers to your questions in different areas. Join our Q&A platform to connect with experts dedicated to providing accurate answers to your questions in various fields.
Sagot :
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
In this exercise we have to use the knowledge of the python language to write the code, so we have to:
The code is in the attached photo.
Some important information informed in the statement that we have to use in the code is:
- Calculate the kilograms, divide the weight by 1000000 and cast the result.
- Calculate the grams, subtract the kilograms from the weight, divide it by 1000 and cast the result.
- Calculate the milligrams, subtract the kilograms and grams from the weight.
So to make it easier the code can be found at:
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))
See more about python at brainly.com/question/26104476
We appreciate your time. Please come back anytime for the latest information and answers to your questions. We hope this was helpful. Please come back whenever you need more information or answers to your queries. Thank you for trusting Westonci.ca. Don't forget to revisit us for more accurate and insightful answers.