write a program to find potential energy PE=mgh, accept mass and height from user.
(g=9.8m/s²)
Answers
pe = lambda m, h: m * 9.81 * h
print("PE:", pe((m := float(input("m: "))), (h := float(input("h: ")))), "J")
Required Answer:-
Question:
- Write a program to find Potential energy. Accept mass and height from the user. (g = 9.8m/s²)
Solution:
★ This is an easy question. We have to take mass and height as input from the user. Then using the formula, we will calculate the potential energy and display.
Here is the code.
It is written in Java.
import java.util.*;
public class PotentialEnergy {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
double g=9.8, m, h, pe;
System.out.print("Enter mass: ");
m=sc.nextDouble();
System.out.print("Enter height: ");
h=sc.nextDouble();
pe=m*g*h;
System.out.println("Potential Energy: "+pe);
}
}
It is written in Python.
g=9.8
m=float(input("Enter mass: "))
h=float(input("Enter height: "))
pe=m*g*h
print("Potential Energy is: ",pe)
Output is attached.