0% found this document useful (0 votes)
4 views6 pages

Python Program

The document contains multiple Python programs demonstrating basic programming concepts such as printing messages, calculating simple interest, determining powers, checking number properties (positive, negative, odd, even), and finding H.C.F. and L.C.M. It also includes programs for temperature conversion, ASCII value retrieval, factorization, and number system conversions. Additionally, there is a program to check if a year is a leap year.

Uploaded by

majestic09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Python Program

The document contains multiple Python programs demonstrating basic programming concepts such as printing messages, calculating simple interest, determining powers, checking number properties (positive, negative, odd, even), and finding H.C.F. and L.C.M. It also includes programs for temperature conversion, ASCII value retrieval, factorization, and number system conversions. Additionally, there is a program to check if a year is a leap year.

Uploaded by

majestic09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

# Python program to print “Hello World”.

print("Hello World")

# Python program to find simple interest.


P=1000
R=5.25
T=2
SI=P*R*T/100
print("Simple Interest=", SI)
………………………………………………………………………………………………………........
..........................

# Python program to compute xn, for given two


integers.
def power(x,n):
return x**n
a=int(input("First Integer for Base:"))
b=int(input("Second Integer for Exponent:"))
print(a," raised to ", b," = ",power(a,b))

………………………………………………………………………………………………………........
..........................

# Python program to Check if a Number is


Positive, Negative or 0

num = float(input("Enter a number: "))


if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")

# Python Program to convert temperature in


celsius to fahrenheit
# change this value for a different result
celsius = 37.5
# calculate fahrenheit
fahrenheit = (celsius * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f
degree Fahrenheit' %(celsius,fahrenheit))

# Python program to check if the input number is


odd or even.
# A number is even if division by 2 give a
remainder of 0.
# If remainder is 1, it is odd number.
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))
# Python program to find the H.C.F of two input
number
# define a function
def computeHCF(x, y):
# choose the smaller number
if x > y:
smaller = y
else:
smaller = x
for i in range(1, smaller+1):
if((x % i == 0) and (y % i == 0)):
hcf = i
return hcf
num1 = 54
num2 = 24
# take input from the user
# num1 = int(input("Enter first number: "))
# num2 = int(input("Enter second number: "))
print("The H.C.F. of", num1,"and", num2,"is",
computeHCF(num1, num2))
# Python Program to find the L.C.M. of two input
number
# define a function
def lcm(x, y):
"""This function takes two
integers and returns the L.C.M."""
# choose the greater number
if x > y:
greater = x
else:
greater = y

while(True):
if((greater % x == 0) and (greater % y ==
0)):
lcm = greater
break
greater += 1

return lcm
# change the values of num1 and num2 for a
different result
num1 = 54
num2 = 24
# uncomment the following lines to take input
from the user
#num1 = int(input("Enter first number: "))
#num2 = int(input("Enter second number: "))
print("The L.C.M. of", num1,"and", num2,"is",
lcm(num1, num2))
# Program to find the ASCII value of the given
character
# Change this value for a different result
c = 'p'
# Uncomment to take character from user
#c = input("Enter a character: ")
print("The ASCII value of '" + c + "'
is",ord(c))
# Python Program to find the factors of a number
# define a function
def print_factors(x):
# This function takes a number and prints the
factors
print("The factors of",x,"are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)
# change this value for a different result.
num = 320
# uncomment the following line to take input
from the user
#num = int(input("Enter a number: "))
print_factors(num)

# Python program to convert decimal number into


binary, octal and hexadecimal number system
# Change this line for a different result
dec = 344
print("The decimal value of",dec,"is:")
print(bin(dec),"in binary.")
print(oct(dec),"in octal.")
print(hex(dec),"in hexadecimal.")

# Python program to check if the input year is a


leap year or not
year = 2000
# To get year (integer input) from the user
# year = int(input("Enter a year: "))
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("{0} is a leap
year".format(year))
else:
print("{0} is not a leap
year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))

You might also like