5.3 (Conversion from kilograms to pounds) Write a program that displays the following table (note 1 kilogram is 2.2 pounds): Kilograms Pounds 2.2 3 6.6 197 433.4 199 437.8
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
How would I write this
Code:Since you have not mentioned the programming language i am providing the code in python
print(format("Kilograms","<10s"),format("Pounds",">10s"))#displaying the heading as required
kilograms = -1#initial value of kilograms is -1
while kilograms <=198:#loop for converting kilograms to pounds
kilograms = kilograms + 2#incrementing the kilograms
pounds = kilograms * 2.2
print(format(kilograms,"<10d"),format(pounds,">10.1f"))#printing the result
Code screenshot:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images