SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Decision Structures And Boolean Logic
Exercise:
Programming Exercises
Question:3 | ISBN:9780132576376 | Edition: 2

Question

Scientists measure an object’s mass in kilograms and its weight in newtons. If you know the amount of mass of an object in kilograms, you can calculate its weight in newtons with the following formula:

weight= mass x 9.8

Write a program that asks the user to enter an object’s mass, and then calculates its weight.If the object weighs more than 1,000 newtons, display a message indicating that it is too heavy. If the object weighs less than 10 newtons, display a message indicating that it is too light.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

CODE:

Mass = float(input("Enter an object’s mass :"))                         #Asking user to enter an object's mass.
Weight = Mass * 9.8                                                      # Converting mass in kilograms to weight in newtons.
Message = ""
if Weight > 1000:                                                       #Checking if weight is above 1000 or not.
    Message = " The object is too heavy at " + format(Weight, ',.2f') +" newtons."     # If it is true update the message.
elif Weight < 10:                                                         #Checking if weight is below 10 or not.
    Message = "The object is too light at"  + format(Weight, ',.2f') + " newtons." # if it is true update the message.
print(Message)                                                                # Display the result 

 

OUTPUT:

Enter an object’s mass :1
The object is too light at9.80 newtons.

Enter an object’s mass :150
 The object is too heavy at 1,470.00 newtons.

 

0 0

Discussions

Post the discussion to improve the above solution.