Print multiplication table of a number:
===========================
num = int(input("Enter the number: "))
print("Multiplication Table of", num)
for i in range(1, 11):
print(num,"X",i,"=",num * i)
Print table of a number:
=================
num = int(input("Enter the number: "))
print("Multiplication Table of", num)
for i in range(1, 11):
print(num * i)
Print sum of n natural number:
=======================
num = int(input("Enter the value of n: "))
hold = num
sum = 0
if num <= 0:
print("Enter a whole positive number!")
else:
while num > 0:
sum = sum + num
num = num - 1;
print("Sum of first", hold, "natural numbers is: ", sum)
Factorial of Number:
================
def factorial(num):
"""This is a recursive function that calls
itself to find the factorial of given number"""
if num == 1:
return num
else:
return num * factorial(num - 1)
num = int(input("Enter a Number: "))
if num < 0:
print("Factorial cannot be found for negative numbers")
elif num == 0:
print("Factorial of 0 is 1")
else:
print("Factorial of", num, "is: ", factorial(num))
Convert decimal to binary:
====================
def decimalToBinary(num):
#This function converts decimal number to binary and prints it
if num > 1:
decimalToBinary(num // 2)
print(num % 2, end='')
number = int(input("Enter any decimal number: "))
decimalToBinary(number)
===========================
num = int(input("Enter the number: "))
print("Multiplication Table of", num)
for i in range(1, 11):
print(num,"X",i,"=",num * i)
Print table of a number:
=================
num = int(input("Enter the number: "))
print("Multiplication Table of", num)
for i in range(1, 11):
print(num * i)
Print sum of n natural number:
=======================
num = int(input("Enter the value of n: "))
hold = num
sum = 0
if num <= 0:
print("Enter a whole positive number!")
else:
while num > 0:
sum = sum + num
num = num - 1;
print("Sum of first", hold, "natural numbers is: ", sum)
Factorial of Number:
================
def factorial(num):
"""This is a recursive function that calls
itself to find the factorial of given number"""
if num == 1:
return num
else:
return num * factorial(num - 1)
num = int(input("Enter a Number: "))
if num < 0:
print("Factorial cannot be found for negative numbers")
elif num == 0:
print("Factorial of 0 is 1")
else:
print("Factorial of", num, "is: ", factorial(num))
Convert decimal to binary:
====================
def decimalToBinary(num):
#This function converts decimal number to binary and prints it
if num > 1:
decimalToBinary(num // 2)
print(num % 2, end='')
number = int(input("Enter any decimal number: "))
decimalToBinary(number)
https://dbaclass.com/monitor-your-db/
No comments:
Post a Comment