Professional Documents
Culture Documents
Python Study Jam D21it171
Python Study Jam D21it171
Area = w * h
Perimeter = 2 * (w + h)
area = 3.14*r**2
circ = 2*3.14*r
c = float(input())
m = (float)(c / 100)
k = (float)(c / 100000)
# Output
print("Length in Meter = ", m, " meter")
print("Length in Kilometer = ", k, " kilometer")
5. WPP to enter value in days and convert in form of years, months and
days (assuming all month has 30 days and year is of 360).
days=int(input("Enter Day:"))
print("Days to Years:",years)
# print("Days to Weeks:",weeks)
print("Days to Months:",months)
print("Days to days:",days)
6. WPP to find power of any number in form of x^y where x and y are
user inputs.
print("Enter the base & exponent values::")
b = int(input())
e = int(input())
r=1
r = pow(b, e)
print("Result:: ", b, "^", e, " = ", r)
c = Thirdangle(a, b)
print("Third Angle of a Triangle = ", c)
D21IT171 Harshal Jethwa
area = (b * h) / 2
print(area)
10. WPP to enter principal amount, time and interest rate. Create
simple_interest(principal, time, rate) function to calculate simple
interest.
def Simple_interest(P,R,T):
print('The principal is', P)
print('The rate of interest is', R)
print('The time period is',T)
Si = (P * R * T)/100
D21IT171 Harshal Jethwa
Simple_interest(P, R, T)
11. WPP to enter principal amount, time and interest rate. Create
compound_interest(principal, time, rate) function to calculate
compound interest.
def compound_interest(principle, rate, time):
result = principle * (pow((1 + rate / 100), time))
return result
amount = compound_interest(p, r, t)
interest = amount - p
print("Compound amount is %.2f" % amount)
print("Compound interest is %.2f" % interest)
D21IT171 Harshal Jethwa
12. Write a Python program that accepts an integer (n) and computes
the value of n+nn+nnn.
Sample value of n is 5
Expected Result : 615
a = int(input("Input an integer : "))
n1 = int( "%s" % a )
n2 = int( "%s%s" % (a,a) )
n3 = int( "%s%s%s" % (a,a,a) )
print (n1+n2+n3)
14. Write a Python program to count the number 4 in a given list. Note
use the given list
def counta(nums):
count = 0
for num in nums:
if num == 4:
count = count + 1
return count
print(counta([1, 3, 4, 5, 3, 24, 2, 4, 5, 2, 222, 32, 4, 10, 3, 4, 50, 100, 4]))
D21IT171 Harshal Jethwa
17. Write a Python program to print all even numbers from a given
numbers list in the same order and stop the printing if any numbers
that come after 27 in the sequence.
numbers = [
33, 2, 5, 12, 23, 55, 6, 78, 9, 27, 56, 7, 89, 4
]
for x in numbers:
if x == 27:
print(x)
break;
elif x % 2 == 0:
D21IT171 Harshal Jethwa
print(x)
19. Write a Python program to get the least common multiple (LCM) of
two positive integers. Note both numbers will be user input.
def compute_lcm(x, y):
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
D21IT171 Harshal Jethwa
lcm = greater
break
greater += 1
return lcm
num1 = float(input())
num2 = float(input())
20. Write a Python program to compute the distance between the points
(x1, y1) and (x2, y2). Note both coordinates will be user input.
print(distance)
import math
x = [4, 0]
y = [6, 6]
distance = math.sqrt( ((x[0]-y[0])**2)+((x[1]-y[1])**2) )
21. Write a python program to sum of the first n positive integers. Note
n will be defined by user.
n = int(input("Input a number: "))
sum = (n * (n + 1)) / 2
print("Sum of the first {0} positive integers:{1}" .format(n,sum))