Professional Documents
Culture Documents
LEAP YEAR
# To get year (integer input) from the user # To take input from the user
if (year % 100) == 0:
# use for loop to iterate 10 times
if (year % 400) == 0:
for i in range(1, 11):
print("{0} is a leap year".format(year)) print(num,'x',i,'=',num*i)
else:
…you can always join us @ faculty of Education, TOPMOST floor(EDB317). We offer MTH201/202, MEE205/206,
MEE203/204, CSC201, EEE201/203, part 1 courses and programing tutorials…Contact Engr marvie for more info.
(08160054997)
…you can always join us @ faculty of Education, TOPMOST floor(EDB317). We offer MTH201/202, MEE205/206,
MEE203/204, CSC201, EEE201/203, part 1 courses and programing tutorials…Contact Engr marvie for more info.
(08160054997)
ADD TWO NUMBERS
num1 = 1
The factorial of a number is the product of all
num2 = 6 the integers from 1 to that number.
print(sum)
Source Code
# Python program to find the factorial of a
PRIME NUMBER
number provided by the user.
Here is source code of the Python Program to check # change the value for a different result
if a number is a prime number. The program output num = 7
is also shown below. # uncomment to take input from the user
a=int(input("Enter number: ")) #num = int(input("Enter a number: "))
k=0
for i in range(2,a//2+1): factorial = 1
if(a%i==0):
k=k+1 # check if the number is negative, positive
if(k<=0): or zero
print("Number is prime") if num < 0:
else: print("Sorry, factorial does not exist
print("Number isn't prime") for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial
of",num,"is",factorial)
…you can always join us @ faculty of Education, TOPMOST floor(EDB317). We offer MTH201/202, MEE205/206,
MEE203/204, CSC201, EEE201/203, part 1 courses and programing tutorials…Contact Engr marvie for more info.
(08160054997)
…you can always join us @ faculty of Education, TOPMOST floor(EDB317). We offer MTH201/202, MEE205/206,
MEE203/204, CSC201, EEE201/203, part 1 courses and programing tutorials…Contact Engr marvie for more info.
(08160054997)
celsius * 1.8 = fahrenheit - 32
num = 12
# calculate the discriminant
d = (b**2) - (4*a*c)
# To take input from the user
# num = int(input("Display
multiplication table of? ")) # find two solutions
sol1 = (-b-cmath.sqrt(d))/(2*a)
Output
ax2 + bx + c = 0, where
Enter a: 1
a, b and c are real numbers and
Enter b: 5
a ≠ 0
Enter c: 6
# Solve the quadratic equation ax**2 +
bx + c = 0 The solutions are (-3+0j) and (-2+0j)
…you can always join us @ faculty of Education, TOPMOST floor(EDB317). We offer MTH201/202, MEE205/206,
MEE203/204, CSC201, EEE201/203, part 1 courses and programing tutorials…Contact Engr marvie for more info.
(08160054997)
…you can always join us @ faculty of Education, TOPMOST floor(EDB317). We offer MTH201/202, MEE205/206,
MEE203/204, CSC201, EEE201/203, part 1 courses and programing tutorials…Contact Engr marvie for more info.
(08160054997)
0x158 in hexadecimal.
Program :
number system. But computer only
understands binary. Binary, octal and
hexadecimal number systems are closely
related and we may require to convert MEAN/AVERAGE
decimal into these systems. Decimal system
is base 10 (ten symbols, 0-9, are used to
represent a number) and similarly, binary is
base 2, octal is base 8 and hexadecimal is num = int(input('How many
base 16. numbers: '))
total_sum = 0
for n in range(num):
A number with the prefix '0b' is considered
numbers = float(input('Enter
binary, '0o' is considered octal and '0x' as
number : '))
hexadecimal. For example:
total_sum += numbers
avg = total_sum/num
print('Average of ', num, '
60 = 0b11100 = 0o74 = 0x3c numbers is :', avg)
0b101011000 in binary.
Code #2 :
# Python code to demonstrate the
0o530 in octal # working of median() on various
…you can always join us @ faculty of Education, TOPMOST floor(EDB317). We offer MTH201/202, MEE205/206,
MEE203/204, CSC201, EEE201/203, part 1 courses and programing tutorials…Contact Engr marvie for more info.
(08160054997)
…you can always join us @ faculty of Education, TOPMOST floor(EDB317). We offer MTH201/202, MEE205/206,
MEE203/204, CSC201, EEE201/203, part 1 courses and programing tutorials…Contact Engr marvie for more info.
(08160054997)
# range of data-sets
Output :
Median of data-set 1 is 5
Median of data-set 3 is 2
Median of data-set 4 is -5
…you can always join us @ faculty of Education, TOPMOST floor(EDB317). We offer MTH201/202, MEE205/206,
MEE203/204, CSC201, EEE201/203, part 1 courses and programing tutorials…Contact Engr marvie for more info.
(08160054997)