0% found this document useful (0 votes)
5 views9 pages

Python Program

The document contains various Python programs for performing different tasks such as converting Celsius to Fahrenheit, finding the largest and smallest among three numbers, checking if a number is even or odd, calculating the area of a triangle and circle, determining leap years, solving quadratic equations, checking for prime numbers, calculating factorials, and reading/writing to files. Each program includes user input and basic control structures to achieve its functionality. Additionally, there are programs for counting uppercase, lowercase letters, and digits in a file, as well as sorting lists in ascending and descending order.

Uploaded by

studyforme853
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)
5 views9 pages

Python Program

The document contains various Python programs for performing different tasks such as converting Celsius to Fahrenheit, finding the largest and smallest among three numbers, checking if a number is even or odd, calculating the area of a triangle and circle, determining leap years, solving quadratic equations, checking for prime numbers, calculating factorials, and reading/writing to files. Each program includes user input and basic control structures to achieve its functionality. Additionally, there are programs for counting uppercase, lowercase letters, and digits in a file, as well as sorting lists in ascending and descending order.

Uploaded by

studyforme853
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

Celsius to Fahrenheit

cel = float(input("Enter celsius value: " ))


F = (cel * 1.8) + 32
print("Fahrenheit = ",F)
Fahrenheit to Celsius
F = float( input("Enter Fahrenheit value: " ))
cel = (F - 32) / 1.8
print("Celcius = ", cel)

Biggest among three number

num1 = float(input("Enter first number: "))


num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if (num1 > num2) and (num1 > num3):
largest = num1
elif (num2 > num1) and (num2 > num3):
largest = num2
else:
largest = num3

print("The largest number is",largest)


Smallest among three number
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if (num1 < num2) and (num1 < num3):
small = num1
elif (num2 < num1) and (num2 < num3):
small = num2
else:
small = num3
print("The smallest number is",small)
Even or odd number
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("Even number",num)
else:
print("Odd number",num)

Area of triangle
a = float(input('Enter first side: '))
b = float(input('Enter second side: '))
c = float(input('Enter third side: '))
s = (a + b + c) / 2
if ((a+b)>c and (b+c)>a and (c+a)>b):
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print("The area of the triangle is:",area)
else :
print("The traingle is not possible")
print("The area of the triangle is:",area)
Leap year program
year= int(input("Enter a year:"))
if (year % 400 == 0) and (year % 100 == 0):
print(" This is a leap year",year)
elif (year % 4 ==0) and (year % 100 != 0):
print("This is a leap year",year)
else:
print("This is not a leap year",year)
Area of circle program
import math as c
R= float (input ("Enter radius :"))
area = [Link]* R * R
print (" The area of circle is: ", area)
Area of circle program using function
import math as c
def findArea(R):
return [Link]* R * R
num=float(input("Enter radius:"))
print("The area of circle is:",findArea(num))
Quadratic equation root finding problem
import math
a = int(input("Enter the value of a: "))
b = int(input("Enter the value of b: "))
c = int(input("Enter the value of c: "))
d = (b**2) - (4*a*c)
if(d > 0):
root1 = (-b + [Link](d) / (2 * a))
root2 = (-b - [Link](d) / (2 * a))
print("Two roots are :",root1, root2)
elif(d == 0):
root1 = root2 = -b / (2 * a)
print("Two equal and real roots are ",root1, root2)
elif(d < 0):
print("The roots are imaginary")
Prime number program
num = int(input("Enter a number: "))
flag = False
if num > 1:
for i in range(2, num):
if (num % i) == 0:
flag = True
break
if flag:
print(num, "is not a prime number")
else:
print(num, "is a prime number")
Factorial number program
n = int(input("Enter a number: "))
f=1
if n < 0:
print("negative numbers")
elif n == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,n + 1):
f = f*i
print("The factorial number is ",f)
File read program
file = open('[Link]', 'r')
data = [Link]()
print(data)
[Link]()
File read and write program

line1 = input("enter your text")


file = open('[Link]', 'a')
[Link](line1)
[Link]()
Add two string in file program
line1 = input("text1")
line2 = input("text2")
line=line1 + line2
file = open('[Link]', 'a')
[Link](line)
[Link]()

File program to count uppercase, lowercase and digit


def program4():
with open("[Link]","r") as f1:
data=[Link]()
ucase =0
lcase=0
digits=0
for ch in data:
if [Link]():
lcase = lcase+1
if [Link]():
ucase = ucase+1
if [Link]():
digits = digits+1
print("Total Upper Case letters are:",ucase)
print("Total Lower Case letters are:",lcase)
print("Total digits are:",digits)
program4()

List program to make ascending order


old_list = [5,-2,15,20,23,-6,27,47]
new_list=[]
while old_list:
minimum = old_list[0]
for x in old_list:
if x < minimum :
minimum = x
new_list.append(minimum)
old_list.remove(minimum)
print(new_list)
List program to make descending order
old_list = [5,-2,15,20,23,-6,27,47]
new_list=[]
while old_list:
maximum = old_list[0]
for x in old_list:
if x > maximum :
maximum = x
new_list.append(maximum)
old_list.remove(maximum)
print(new_list)

You might also like