0% found this document useful (0 votes)
23 views3 pages

Programs

The document contains code snippets demonstrating different Python programming concepts like data types, user input, arithmetic operations, functions, and importing modules. The snippets include programs to calculate simple interest, area of a triangle, square root of a number, temperature conversion between Fahrenheit and Celsius, and displaying a calendar for a given month and year.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Programs

The document contains code snippets demonstrating different Python programming concepts like data types, user input, arithmetic operations, functions, and importing modules. The snippets include programs to calculate simple interest, area of a triangle, square root of a number, temperature conversion between Fahrenheit and Celsius, and displaying a calendar for a given month and year.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Type function

x = 10
print(type(x))

a = ("Geeks", "for",
"Geeks")
b = ["Geeks", "for",
"Geeks"]
c = {"Geeks": 1, "for":2,
"Geeks":3}
d = "Hello World"
e = 10.23
f = 11.22
print(type(a))
print(type(b))
print(type(c))
print(type(d))
print(type(e))
print(type(f))

Add 2 numbers
num1 = 15
num2 = 12
sum = num1 + num2
# printing values
print("Sum of", num1, "and", num2 , "is",
sum)
Adding 2 number taking user input
number1 = input("First number: ")
number2 = input("\nSecond number: ")
# Adding two numbers
# User might also enter float numbers
sum = float(number1) + float(number2)
# Display the sum
# will print value in float
print("The sum of {0} and {1} is {2}"
.format(number1,number2, sum))

Program to calculate simple interest


def simple_interest(p,t,r):
print('The principal is', p)
print('The time period is', t)
print('The rate of interest is',r)
si = (p * t * r)/100
print('The Simple Interest is', si)
return si
# Driver code
simple_interest(8, 6, 8)
Program to calculate area of a triangle
# Three sides of the triangle is a, b and c:
a = float(input('Enter first side: '))
b = float(input('Enter second side: '))
c = float(input('Enter third side: '))
# calculate the semi-perimeter
s = (a + b + c) / 2
# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)
Program to find out square root of a number
# import complex math module
import cmath
a = float(input('Enter a: '))
b = float(input('Enter b: '))
c = float(input('Enter c: '))
# calculate the discriminant
d = (b**2) - (4*a*c)
# find two solutions
sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)
print('The solution are {0} and {1}'.format(sol1,sol2))
Program to convert F to C
celsius_1 = float(input("Temperature value in degree Celsius: " ))
# For Converting the temperature to degree Fahrenheit by usi
ng the above
# given formula
Fahrenheit_1 = (celsius_1 * 1.8) + 32
# print the result
print('The %.2f degree Celsius is equal to: %.2f Fahrenheit'
%(celsius_1, Fahrenheit_1))
print("----OR----")
celsius_2 = float (input("Temperature value in degree Celsius: "
))
Fahrenheit_2 = (celsius_2 * 9/5) + 32
# print the result
print ('The %.2f degree Celsius is equal to: %.2f Fahrenheit'
%(celsius_2, Fahrenheit_2))
Program to import calendar
import calendar
# Enter the month and year
yy = int(input("Enter year: "))
mm = int(input("Enter month: "))
# display the calendar
print(calendar.month(yy,mm))

You might also like