8000 Added few programs · enthuleo/programminginpython.com@0ebd888 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ebd888

Browse files
authored
Added few programs
1 parent e8fbe52 commit 0ebd888

7 files changed

+107
-0
lines changed

arithmeticOperations.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
__author__ = 'Avinash'
2+
3+
num1 = int(input('Enter First number: '))
4+
num2 = int(input('Enter Second number '))
5+
add = num1 + num2
6+
dif = num1 - num2
7+
mul = num1 * num2
8+
div = num1 / num2
9+
floor_div = num1 // num2
10+
power = num1 ** num2
11+
modulus = num1 % num2
12+
print('Sum of ', num1, 'and', num2, 'is :', add)
8000 13+
print('Difference of ', num1, 'and', num2, 'is :', dif)
14+
print('Product of ', num1, 'and', num2, 'is :', mul)
15+
print('Division of ', num1, 'and', num2, 'is :', div)
16+
print('Floor Division of ', num1, 'and', num2, 'is :', floor_div)
17+
print('Exponent of ', num1, 'and', num2, 'is :', power)
18+
print('Modulus of ', num1, 'and', num2, 'is :', modulus)
19+

average.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
__author__ = 'Avinash'
2+
3+
num = int(input('How many numbers: '))
4+
total_sum = 0
5+
6+
for n in range(num):
7+
numbers = float(input('Enter number : '))
8+
total_sum += numbers
9+
10+
avg = total_sum/num
11+
print('Average of ', num, ' numbers is :', avg)

even_odd.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
__author__ = 'Avinash'
2+
3+
input_num = int(input('Enter any number: '))
4+
5+
if input_num % 2 == 0:
6+
print(input_num, "is EVEN")
7+
else:
8+
print(input_num, "is ODD")

listOperations.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
__author__ = 'Avinash'
2+
3+
lst = ['abc', 'def', 'ghi', 'jklm', 'nopqr', 'st', 'uv', 'wxyz', '23', 's98', '123', '87']
4+
5+
# prints the length of the list
6+
print('Length of the list is : ', len(lst))
7+
8+
# appends an item to the list
9+
lst.append('sdd')
10+
print('\nThe list appended a new element "sdd" at the end \n', lst)
11+
12+
# changes the value of an item in a list
13+
lst[0] = 'aaa'
14+
print('\nThe value of the first element in the list is changed to "aaa" \n', lst)
15+
16+
# Slicing
17+
# shows only items starting from 0 upto 3
18+
print('\nList showing only items starting from 0 upto 3\n', lst[:3])
19+
20+
# shows only items starting from 4 to the end
21+
print('\nList showing only items starting from 4 to the end\n', lst[4:])
22+
23+
# shows only items starting from 2 upto 6
24+
print('\nList showing only items starting from 2 upto 6\n', lst[2:6])
25+
26+
# reverse all items in the list
27+
print('\nList items reversed \n', lst[::-1])
28+
29+
# removing items from list
30+
lst[:1] = []
31+
print('\nFirst element is removed from the list \n', lst)
32+
33+
# removing whole list
34+
lst[:] = []
35+
print('\nComplete list removed \n', lst)

number_reverse.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
__author__ = 'Avinash'
2+
3+
input_num = (input("Enter any number: "))
4+
reverse = 0
5+
try:
6+
val = int(input_num)
7+
while val > 0:
8+
reminder = val % 10
9+
reverse = (reverse * 10) + reminder
10+
val //= 10
11+
print('Reverse of given number is : ', reverse)
12+
except ValueError:
13+
print("That's not a valid number, Try Again !")

number_reverse_slice.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
__author__ = 'Avinash'
2+
3+
num = input('Enter any number : ')
4+
5+
try:
6+
val = int(num)
7+
print('Reverse of the given number is : ', str(num)[::-1])
8+
except ValueError:
9+
print("That's not a valid number, Try Again !")
10+

palindrome.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
__author__ = 'Avinash'
2+
3+
num = input('Enter any number : ')
4+
try:
5+
val = int(num)
6+
if num == str(num)[::-1]:
7+
print('The given number is PALINDROME')
8+
else:
9+
print('The given number is NOT a palindrome')
10+
except ValueError:
11+
print("That's not a valid number, Try Again !")

0 commit comments

Comments
 (0)
0