Respuesta :
Answer:
import java.util.Scanner;
public class TestClock {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter Value in grams");
double grams = in.nextDouble();
double pounds = 453.592*grams;
System.out.println(grams+" grams is equal to "+pounds+" pounds");
}
}
Explanation:
- Import the Scanner Class to receive user input
- Save the user input in a variable
- Use the conversion 1 pound = 453.592 grams to calculate the equivalent grams
- Output the the value of pounds calculated
The program that converts grams to pounds is as follows;
def grams_to_pounds(x):
weight_in_pounds = x / 453.592
return weight_in_pounds
w1 = grams_to_pounds(500)
w2 = grams_to_pounds(1000)
w3 = grams_to_pounds(2000)
print(w1)
print(w2)
print(w3)
Code explanation
- A function grams_to_pounds is declared with an argument x . The argument x is the mass in grams.
- The variable weight_in_pounds is use to store the value of when the mass in grams is divided by 453.592
- Finally, we call our function with it parameter, using the variables w1, w2 and w3 to store it.
- The print statement is use to print the variables.
learn more on python code here: https://brainly.com/question/1620423?referrer=searchResults
