Skip to content

Commit 056035e

Browse files
Add files via upload
1 parent f86f020 commit 056035e

6 files changed

+798
-0
lines changed

2.1_Python_Numbers.py

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#Mathematical Functions in Python | Set 1 (Numeric Functions)
2+
3+
# 1)ceil() and floor()
4+
# importing "math" for mathematical operations
5+
6+
'''import math
7+
a = 2.3
8+
9+
# returning the ceil of 2.3
10+
print ("The ceil of 2.3 is : ", end="")
11+
print (math.ceil(a))
12+
13+
# returning the floor of 2.3
14+
print ("The floor of 2.3 is : ", end="")
15+
print (math.floor(a))'''
16+
17+
# 2) Python code to demonstrate the working of
18+
# fabs() and factorial()
19+
20+
# importing "math" for mathematical operations
21+
'''import math
22+
23+
a = -10
24+
b= 5
25+
26+
# returning the absolute value.
27+
print ("The absolute value of -10 is : ", end="")
28+
print (math.fabs(a))
29+
30+
# returning the factorial of 5
31+
print ("The factorial of 5 is : ", end="")
32+
print (math.factorial(b))'''
33+
34+
# Python code to demonstrate the working of
35+
# copysign() and gcd()
36+
37+
# importing "math" for mathematical operations
38+
'''import math
39+
40+
a = -10
41+
b = 5.5
42+
c = 15
43+
d = 5
44+
45+
# returning the copysigned value.
46+
print ("The copysigned value of -10 and 5.5 is : ", end="")
47+
print (math.copysign(5.5, -10))
48+
49+
# returning the gcd of 15 and 5
50+
print ("The gcd of 5 and 15 is : ", end="")
51+
print (math.gcd(5,15))'''
52+
53+
# Python code to demonstrate the working of
54+
# exp() and log()
55+
56+
# importing "math" for mathematical operations
57+
'''import math
58+
59+
# returning the exp of 4
60+
print ("The e**4 value is : ", end="")
61+
print (math.exp(4))
62+
63+
# returning the log of 2,3
64+
print ("The value of log 2 with base 3 is : ", end="")
65+
print (math.log(2,3))'''
66+
67+
# Python code to demonstrate the working of
68+
# log2() and log10()
69+
70+
# importing "math" for mathematical operations
71+
'''import math
72+
73+
# returning the log2 of 16
74+
print ("The value of log2 of 16 is : ", end="")
75+
print (math.log2(16))
76+
77+
# returning the log10 of 10000
78+
print ("The value of log10 of 10000 is : ", end="")
79+
print (math.log10(10000))'''
80+
81+
# Python code to demonstrate the working of
82+
# pow() and sqrt()
83+
84+
# importing "math" for mathematical operations
85+
'''import math
86+
87+
# returning the value of 3**2
88+
print ("The value of 3 to the power 2 is : ", end="")
89+
print (math.pow(3,2))
90+
91+
# returning the square root of 25
92+
print ("The value of square root of 25 : ", end="")
93+
print (math.sqrt(25))'''
94+
95+
# Python code to demonstrate the working of
96+
# sin() and cos()
97+
98+
# importing "math" for mathematical operations
99+
'''import math
100+
101+
a = math.pi/6
102+
103+
# returning the value of sine of pi/6
104+
print ("The value of sine of pi/6 is : ", end="")
105+
print (math.sin(a))
106+
107+
# returning the value of cosine of pi/6
108+
print ("The value of cosine of pi/6 is : ", end="")
109+
print (math.cos(a))'''
110+
111+
# Python code to demonstrate the working of
112+
# tan() and hypot()
113+
114+
# importing "math" for mathematical operations
115+
'''import math
116+
117+
a = math.pi/6
118+
b = 3
119+
c = 4
120+
121+
# returning the value of tangent of pi/6
122+
print ("The value of tangent of pi/6 is : ", end="")
123+
print (math.tan(a))
124+
125+
# returning the value of hypotenuse of 3 and 4
126+
print ("The value of hypotenuse of 3 and 4 is : ", end="")
127+
print (math.hypot(b,c))'''
128+
129+
# Python code to demonstrate the working of
130+
# degrees() and radians()
131+
132+
# importing "math" for mathematical operations
133+
'''import math
134+
135+
a = math.pi/6
136+
b = 30
137+
138+
# returning the converted value from radians to degrees
139+
print ("The converted value from radians to degrees is : ", end="")
140+
print (math.degrees(a))
141+
142+
# returning the converted value from degrees to radians
143+
print ("The converted value from degrees to radians is : ", end="")
144+
print (math.radians(b))'''
145+
146+
# Python code to demonstrate the working of
147+
# gamma()
148+
149+
# importing "math" for mathematical operations
150+
'''import math
151+
152+
a = 4
153+
154+
# returning the gamma() of 4
155+
print ("The gamma() of 4 is : ", end="")
156+
print (math.gamma(a))'''
157+
158+
# Python code to demonstrate the working of
159+
# const. pi and e
160+
161+
# importing "math" for mathematical operations
162+
'''import math
163+
164+
# returning the value of const. pi
165+
print ("The value of const. pi is : ", end="")
166+
print (math.pi)
167+
168+
# returning the value of const. e
169+
print ("The value of const. e is : ", end="")
170+
print (math.e)'''
171+
172+
# Python code to demonstrate the working of
173+
# inf, nan, isinf(), isnan()
174+
175+
# importing "math" for mathematical operations
176+
'''import math
177+
178+
# checking if number is nan
179+
if (math.isnan(math.nan)):
180+
print ("The number is nan")
181+
else : print ("The number is not nan")
182+
183+
# checking if number is positive infinity
184+
if (math.isinf(math.inf)):
185+
print ("The number is positive infinity")
186+
else : print ("The number is not positive infinity")'''
187+
188+
189+

2.2 .a Python Lists.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
"""#1)List Index
2+
3+
my_list = ['k','a','r','t','h','i','k']
4+
# Output: k
5+
print(my_list[0])
6+
# Output: r
7+
print(my_list[2])
8+
# Output: h
9+
print(my_list[4])
10+
# Output: 1
11+
print(my_list.index('a'))
12+
# Output: 2
13+
print(my_list.count('k'))
14+
# Error! Only integer can be used for indexing:type error
15+
print(my_list[4.0])
16+
# Nested List
17+
n_list = ["Happy", [2,0,1,5]]
18+
# Nested indexing
19+
# Output: a
20+
print(n_list[0][1])
21+
# Output: 5
22+
print(n_list[1][3])"""
23+
24+
25+
#2)Negative indexing
26+
27+
"""my_list = ['k','a','r','t','h','i','k']
28+
# Output: k
29+
print(my_list[-1])
30+
# Output: r
31+
print(my_list[-5])"""
32+
33+
#We can access a range of items in a list by using the slicing operator (colon).
34+
35+
"""my_list = ['k','a','r','t','h','i','k',]
36+
# elements 3rd to 5th
37+
print(my_list[2:5])
38+
# elements beginning to 4th
39+
print(my_list[:-5])
40+
# elements 5th to end
41+
print(my_list[5:])
42+
# elements beginning to end
43+
print(my_list[:])"""
44+
45+
#We can use assignment operator (=) to change an item or a range of items.
46+
47+
"""# mistake values
48+
even = [2, 4, 6, 8]
49+
# change the 1st item
50+
even[0] = 1
51+
# Output: [1, 4, 6, 8]
52+
print(even)
53+
# change 2nd to 4th items
54+
even[1:4] = [3, 5, 7]
55+
# Output: [1, 3, 5, 7]
56+
print(even)"""
57+
58+
#We can add one item to a list using append() method or add several items using extend() method.
59+
60+
"""odd = [1, 3, 5]
61+
odd.append(7)
62+
# Output: [1, 3, 5, 7]
63+
print(odd)
64+
odd.extend([9, 11, 13])
65+
# Output: [1, 3, 5, 7, 9, 11, 13]
66+
print(odd)"""
67+
68+
#We can also use + operator to combine two lists. This is also called concatenation.
69+
#The * operator repeats a list for the given number of times.
70+
71+
""""odd = [1, 3, 5]
72+
# Output: [1, 3, 5, 9, 7, 5]
73+
print(odd + [9, 7, 5])
74+
#Output: ["re", "re", "re"]
75+
print(["re"] * 3)"""
76+
77+
#insert one item we use can insert() method
78+
79+
"""odd = [1, 9]
80+
odd.insert(1,3)
81+
# Output: [1, 3, 9]
82+
print(odd)
83+
odd[2:2] = [5, 7]
84+
# Output: [1, 3, 5, 7, 9]
85+
print(odd)"""
86+
87+
#We can delete one or more items from a list using the keyword del.
88+
89+
"""my_list = ['p','r','o','b','l','e','m']
90+
# delete one item
91+
del my_list[2]
92+
# Output: ['p', 'r', 'b', 'l', 'e', 'm']
93+
print(my_list)
94+
# delete multiple items
95+
del my_list[1:5]
96+
# Output: ['p', 'm']
97+
print(my_list)
98+
# delete entire list
99+
del my_list
100+
# Error: List not defined
101+
print(my_list)"""
102+
103+
#We can also use the clear() method to empty a list.
104+
105+
"""my_list = ['p','r','o','b','l','e','m']
106+
my_list.remove('p')
107+
# Output: ['r', 'o', 'b', 'l', 'e', 'm']
108+
print(my_list)
109+
# Output: 'o'
110+
print(my_list.pop(1))
111+
# Output: ['r', 'b', 'l', 'e', 'm']
112+
print(my_list)
113+
# Output: 'm'
114+
print(my_list.pop())
115+
# Output: ['r', 'b', 'l', 'e']
116+
print(my_list)
117+
my_list.clear()
118+
# Output: []
119+
print(my_list)"""
120+
121+
#We can test if an item exists in a list or not, using the keyword in.
122+
123+
"""my_list = ['p','r','o','b','l','e','m']
124+
# Output: True
125+
print('p' in my_list)
126+
# Output: False
127+
print('a' in my_list)
128+
# Output: True
129+
print('c' not in my_list)"""
130+
131+
#Using a for loop we can iterate though each item in a list.
132+
"""for fruit in ['apple','banana','mango']:
133+
print("I like",fruit)"""
134+
135+
136+
137+
138+
139+
140+
141+

0 commit comments

Comments
 (0)