Python Programs Flashcards
How many seconds are there in 42 minutes 42 seconds?
# Converts Minutes to Seconds minutes = int(input("Entern Minutes : ")) seconds = int(input("Enter Seconds : ")) print(f"Total Seconds are : {(minutes * 60)+seconds}")
How many miles are there in 10 kilometers? Hint: there are 1.61 kilometers in a
mile.
Converts Kilometers to Miles
The volume of a sphere with radius r is 4
3πr3. What is the volume of a sphere with
radius 5?
radius = int(input("Enter Radius : ")) cubeOfradius = radius ** 3 pie = 3.14 v = 4/3 * (cubeOfradius * pie) print(f"Volume of Sphere is : {v:,.2f}")
How many miles are there in 10 kilometers? Hint: there are 1.61 kilometers in a mile.
kms = int(input(“Enter Kilometers : “))
oneMile = 1.61
totalMiles = kms / oneMile
print(f”There is {totalMiles:,.2f} Miles in {kms} Kilometers”)
The volume of a sphere with radius r is 4
3πr3. What is the volume of a sphere with
radius 5?
radius = int(input("Enter Radius : ")) cubeOfradius = radius ** 3 pie = 3.14 v = 4/3 * (cubeOfradius * pie) print(f"Volume of Sphere is : {v:,.2f}")
If you run a 10 kilometer race in 42 minutes 42 seconds, what is your average
pace (time per mile in minutes and seconds)? What is your average speed in
miles per hour?
42minute+42sec=2580 second
2580 socond /3600=0.7166 hr
0.7166 hr me 10km
So 1 hr me - 10/0.7166= 13.95km
13.95 km/1.61= 8.66 mile
#python Code seconds = (42 * 60) + 42 print("Seconds = ",seconds)
hours = seconds / 3600 print(f"Hours = {hours:,.2f}")
kms_in_OneHour = 10 / hours
print(f”Average Speed in Kms Per Hour is : {kms_in_OneHour:,.2f}”)
miles_in_oneHour = kms_in_OneHour / 1.61
print(f”Average Speed in Miles Per Hour is : {miles_in_oneHour:,.2f}”)
#output Seconds = 2562 Hours = 0.71 Average Speed in Kms Per Hour is : 14.05 Average Speed in Miles Per Hour is : 8.73
How to print value of pie twice using a function .
import math def printTwice(value): print(value) print(value) printTwice(math.pi)
Program for Divide,Modulus & Floor Division
x,y = 9,2
print(f”{x} dvided by {y} = {x/y:,.2f}”)
print(f”{x} Modulas {y} = {x%y}”)
print(f”{x} Floor Division {y} = {x//y}”)
if we multiply a list to 3 ,then what would happen ?
list contents are concatinated by three times. list1 = [1,2,3,4] list1 = list1*3 print(list1) Outupt - [1,2,3,4,1,2,3,4,1,2,3,4]