A little bit of math for Python
So far we have introduced the computer to two types of numbers:
float: numbers with a decimal
int: whole numbers
int: whole numbers
adding = 4 + 3
print(adding)
subtraction = 8 - 9
print(subtraction)
multiplication = 4 * 32
print(multiplication)
division = 50 / 5
print(division)
# a number raised to the power of some number
# in this example we raise 5 to the power of 2
squared = 5**2
print(squared)
# remainder of a division
modulo = 15 % 4
print(modulo)
# whole number division
divisor = 15 // 2
print(divisor)
Lets get into coding again :
tMinutes = int(input("1 hour in Minutes=:"))
tHours = int(input("1 Day in Hours=:" ))
#tDays = int(input("1 year in Days:"))
tYear = int(input("which year it is"))
# lets check for the leap year
if tYear % 4 == 0:
tDays = 366
Totalsecs = tDays*tHours*tMinutes*tSeconds
print("total seconds in year =",Totalsecs)
else:
tDays = 365
Totalsecs = tDays*tHours*tMinutes*tSeconds
print("total seconds in year =",Totalsecs)
No comments:
Post a Comment