-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.py
More file actions
115 lines (99 loc) · 3.13 KB
/
python.py
File metadata and controls
115 lines (99 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#print hello world
print("Hello, World!")
#print the sum of two numbers
a=10
b=20
sum=a+b
print("The sum of a and b is:",sum)
#print the basic information of a person
Name="Shruti"
age=18
branch="cys"
phone=234567891
print("My name is :",Name)
print("My age is:",age)
print("Branch:",branch)
print("My phone number is:",phone)
#swap the values of two variables using a temporary variable
a=10
b=20
temp=a
a=b
b=temp
print("The value of a after swapping:",a)
print("The value of b after swapping:",b)
#swap the values of two variables without using a temporary variable
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
a = a + b
b = a - b
a = a - b
print("After swapping:")
print("First number:", a)
print("Second number:", b)
#print perimeter and area of a triangle
import math
a = float(input("Enter the first side of the triangle: "))
b = float(input("Enter the second side of the triangle: "))
c = float(input("Enter the third side of the triangle: "))
# Calculating the perimeter
perimeter = a + b + c
print("Perimeter of the triangle:", perimeter)
# Using Heron's formula to calculate the area
# Semi-perimeter (s)
s = perimeter / 2
# Area calculation
area = math.sqrt(s * (s - a) * (s - b) * (s - c))
print("Area of the triangle:", area)
#program to convert temperature from Celsius to Fahrenheit
f= float(input("Enter temperature in Fahrenheit: "))
c= (f - 32) * 5 / 9
print("Temperature in Celsius:", c)
#program to calculate the simple interest
p= float(input("Enter the principal amount: "))
r= float(input("Enter the rate of interest: "))
t= float(input("Enter the time period: "))
si= (p * r * t) / 100
print("Simple Interest:", si)
#program to calculate the compound interest
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the annual rate of interest (in %): "))
time = float(input("Enter the time (in years): "))
compound_interest = principal * (1 + rate / 100)**time - principal
print("The compound interest is:", compound_interest)
#program to find smallest number among three numbers
a = int(input("Enter the first value: "))
b = int(input("Enter the second value: "))
c = int(input("Enter the third value: "))
if a < b and a < c:
print("The smallest number is:", a)
elif b < a and b < c:
print("The smallest number is:", b)
else:
print("The smallest number is:", c)
#program to print info using format function
Name="Shruti"
age=18
branch="cys"
CGPA=9.26
print("name is {} age is{} branch is {} and CGPA is {}" .format(Name,age,branch,CGPA))
#program to print area of a circle using format function
import math
r=float(input("Enter the radius of circle:"))
area=math.pi*r*r
print("area of circle is: {}" .format(area))
#Celcius to Fahrenhite using .format
c=float(input("Enter the temperature in celcius:"))
f=(c*9/5)+32
print("Temperature in Fahrenhite is: {}" .format(f))
#factorial of number
a=int(input("Enter the number:"))
fact=1
for i in range(1,a+1):
fact=fact*i
print("The factorial of {} is {}" .format(a,fact))
#quotient and remainder of given number
a=int(input("Enter the number:"))
b=int(input("Enter the number:"))
print(a//b)
print(a%b)