Skip to content

Commit 7748505

Browse files
authored
Add files via upload
1 parent 2b1e396 commit 7748505

37 files changed

+306
-0
lines changed

Python/1 To N Using Loop.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Program to print from 1 to n using loop
2+
n = int(input("Enter the range: "))
3+
for i in range (0, n + 1):
4+
print(i)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Program to print all even numbers within a given range
2+
a = int(input("Enter the start of the range: "))
3+
b = int(input("Enter the end of the range: "))
4+
print("Even numbers in the given range are")
5+
for i in range(a, b + 1):
6+
if i % 2 == 0:
7+
print(i)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Program to print all odd numbers within a given range
2+
a = int(input("Enter the start of the range: "))
3+
b = int(input("Enter the end of the range: "))
4+
print("Odd numbers in the given range are")
5+
for i in range(a, b + 1):
6+
if i % 2 == 0:
7+
pass
8+
else:
9+
print(i)

Python/Area Of A Circle.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Program to find the area of a circle
2+
import math
3+
r = float(input("Enter the radius: "))
4+
area = math.pi * r * r
5+
print("The area is", round(area, 2))

Python/Area Of A Rectangle.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Program to find the area of a rectangle
2+
a = float(input("Enter the length: "))
3+
b = float(input("Enter the breadth: "))
4+
area = a * b
5+
print("The area is", round(area, 2))

Python/Area Of A Square.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Program to find the area of a square
2+
a = float(input("Enter the side: "))
3+
area = a * a
4+
print("The area is", round(area, 2))

Python/Area Of A Traingle.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Program to find the area of a triangle
2+
b = float(input("Enter the base: "))
3+
h = float(input("Enter the height: "))
4+
area = 1/2 * b * h
5+
print("The area is", round(area, 2))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Program to print an arithmetic progression series
2+
a = int(input("Enter the first number of the series: "))
3+
b = int(input("Enter the common difference of the series: "))
4+
n = int(input("Enter the number of terms of the series :"))
5+
print("The AP series from", a, "with common difference of", b, "with total of", n, "terms is")
6+
for i in range(0, n):
7+
s = a + i * b
8+
print(s, end = " ")

Python/Armstrong Number.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Program to check if a number is armstrong or not
2+
n = int(input("Enter the number: "))
3+
temp = n
4+
s = 0
5+
num = len(str(n))
6+
while temp > 0:
7+
r = temp % 10
8+
s += r ** num
9+
temp //= 10
10+
if n == s:
11+
print(s, "is an armstrong number")
12+
else:
13+
print(s, "is not an armstrong number")

Python/Basic Calculator.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Program to create a basic calculator
2+
a = float(input("Enter the first number: "))
3+
b = float(input("Enter the second number: "))
4+
c = int(input("1 for Addition\n2 for Subtraction\n3 for Multiplication\n4 for Division\n5 for Floor Division\n6 for Exponentiation\n7 for Modulus\nEnter your choice: "))
5+
if c == 1:
6+
sum = a + b
7+
elif c == 2:
8+
sum = a - b
9+
elif c == 3:
10+
sum = a * b
11+
elif c == 4:
12+
sum = a / b
13+
elif c == 5:
14+
sum = a // b
15+
elif c == 6:
16+
sum = a ** b
17+
elif c == 7:
18+
sum = a % b
19+
else:
20+
print("You have entered wrong input")
21+
exit()
22+
print("The answer is", round(sum, 2))

0 commit comments

Comments
 (0)