Python Practice Programs for Beginners
Python Practice Programs for Beginners
By using the modulus operator (%), you can extract each digit from the number. For example, with number n: the last digit is n % 10, the second digit is (n/10) % 10, and the first digit is n/100. These extracted digits can then be recombined in reverse order .
Total energy is calculated by summing up kinetic and potential energy: E = (mv^2 / 2) + mgh, where m is mass, v is velocity, g is gravitational acceleration, and h is height .
First, calculate the number of hours by dividing the total seconds by 3600. Then, determine the remaining seconds and calculate the minutes by dividing those by 60. The leftover seconds are the final seconds value .
Swapping two integers without a third variable can be done via arithmetic operations: let a = a + b, b = a - b, and a = a - b. Using a third variable involves storing one of the numbers: temp = a, a = b, and b = temp .
For the area, use the formula: area = 1/2 * base * height. For the perimeter, sum the lengths of all sides: perimeter = a + b + c, where a, b, and c are the side lengths .
To calculate the aggregate marks, sum the marks obtained in all five subjects. The percentage marks can be calculated using the formula: (total marks obtained / 500) * 100, since the maximum marks per subject are 100, making the total maximum marks 500 .
Velocity can be determined by dividing the distance by the time: velocity = distance / time .
The program should implement the formula to convert Fahrenheit to Centigrade: C = (F - 32) * 5/9, where C stands for Centigrade and F stands for Fahrenheit .
Centripetal force is calculated using the formula F = mv^2 / r, where m is the mass, v is the velocity, and r is the radius. The force depends directly on the mass and the square of velocity, and inversely on the radius .
Final velocity can be calculated using the formula v = u + at. The distance traveled can be computed using s = ut + 1/2at^2, where u is the initial velocity, a is the acceleration, t is the time, v is the final velocity, and s is the distance .