8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e8fbe52 commit 0ebd888Copy full SHA for 0ebd888
arithmeticOperations.py
@@ -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)
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
@@ -0,0 +1,11 @@
+num = int(input('How many numbers: '))
+total_sum = 0
+for n in range(num):
+ numbers = float(input('Enter number : '))
+ total_sum += numbers
+avg = total_sum/num
+print('Average of ', num, ' numbers is :', avg)
even_odd.py
@@ -0,0 +1,8 @@
+input_num = int(input('Enter any number: '))
+if input_num % 2 == 0:
+ print(input_num, "is EVEN")
+else:
+ print(input_num, "is ODD")
listOperations.py
@@ -0,0 +1,35 @@
+lst = ['abc', 'def', 'ghi', 'jklm', 'nopqr', 'st', 'uv', 'wxyz', '23', 's98', '123', '87']
+# prints the length of the list
+print('Length of the list is : ', len(lst))
+# appends an item to the list
+lst.append('sdd')
+print('\nThe list appended a new element "sdd" at the end \n', lst)
+# changes the value of an item in a list
+lst[0] = 'aaa'
+print('\nThe value of the first element in the list is changed to "aaa" \n', lst)
+# Slicing
+# shows only items starting from 0 upto 3
+print('\nList showing only items starting from 0 upto 3\n', lst[:3])
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
@@ -0,0 +1,13 @@
+input_num = (input("Enter any number: "))
+reverse = 0
+try:
+ val = int(input_num)
+ while val > 0:
+ reminder = val % 10
+ reverse = (reverse * 10) + reminder
+ val //= 10
+ print('Reverse of given number is : ', reverse)
+except ValueError:
+ print("That's not a valid number, Try Again !")
number_reverse_slice.py
@@ -0,0 +1,10 @@
+num = input('Enter any number : ')
+ val = int(num)
+ print('Reverse of the given number is : ', str(num)[::-1])
palindrome.py
+ if num == str(num)[::-1]:
+ print('The given number is PALINDROME')
+ else:
+ print('The given number is NOT a palindrome')