Skip to content

Commit bfd7300

Browse files
authored
Merge pull request #3 from Patelvijaykumar/python_module_ranmon_and_math
added example of python module math and random
2 parents aacdf24 + 7bbc13a commit bfd7300

File tree

4 files changed

+163
-0
lines changed

4 files changed

+163
-0
lines changed

Python-String/String-example1.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Python String Variable Demostration
2+
3+
# Declaration
4+
5+
#String Declaration with single quote for single line display
6+
x= ''
7+
print (x)
8+
9+
#String Declaration with double quote for single line display
10+
x= " "
11+
print (x)
12+
13+
#String Declaration with multi line print with single quote
14+
x = '''Hello
15+
This is Python Multiline
16+
demo
17+
'''
18+
print (x)
19+
20+
21+
#String Declaration with multi line print with double quote
22+
x = """Hello
23+
This is Python Multiline
24+
demo
25+
"""
26+
print (x)
27+
28+
#How print works
29+
x= 'hello'
30+
#variable will br printed
31+
print (x)
32+
33+
#x as a string will be printted
34+
print ('x')
35+
36+
#x as a string will be printted
37+
print ("x")
38+
39+
#variable x will be printed in string conversation
40+
print (str(x))
41+
42+
#repr() representation that has all information
43+
print (repr(x))

Python-String/String-example2.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Python String Variable Demostration
2+
3+
# Declaration
4+
x="python"
5+
6+
#condition in string with small latter
7+
print ('t' in x)
8+
9+
10+
#condition in string with capital latter
11+
print ('T' in x)
12+
13+
#String print
14+
print (x)
15+
16+
# String lenght printed
17+
print (len(x))
18+
19+
#How to add new line in print
20+
x= "Python\nTest"
21+
print(x)
22+
23+
#How to add new line in print
24+
x= 'Python\nTest'
25+
print(x)
26+
27+
#How to avoide special character
28+
x = r'Python\nTest'
29+
print (x)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#Python | math() function
2+
3+
import math
4+
5+
# Python code to demonstrate the working of
6+
7+
#demonstrate of math module to pi value
8+
print ("The pi value is : ", end="")
9+
print (math.pi)
10+
11+
#demonstrate of math module to math e value
12+
print ("The math e value is : ", end="")
13+
print (math.e)
14+
15+
#demonstrate of math module sin formula
16+
print ("The sin(10) value is : ", end="")
17+
print (math.sin(10))
18+
19+
#demonstrate of math module cos formula
20+
print ("The cos(10) value is : ", end="")
21+
print (math.cos(10))
22+
23+
#demonstrate of math module log10 formula
24+
print ("The log10(10) value is : ", end="")
25+
print (math.log10(10))
26+
27+
#demonstrate of math module for factorial function
28+
print ("The factorial value of 5 is : ", end="")
29+
print (math.factorial(5))
30+
31+
#demonstrate of math module for square root function
32+
print ("The square root value of 9 is : ", end="")
33+
print (math.sqrt(9))
34+
35+
# Python code to demonstrate the working of
36+
# ceil() and floor()
37+
38+
a = 2.3
39+
40+
# returning the ceil of 2.3
41+
print ("The ceil of 2.3 is : ", end="")
42+
print (math.ceil(a))
43+
44+
# returning the floor of 2.3
45+
print ("The floor of 2.3 is : ", end="")
46+
print (math.floor(a))
47+
48+
49+
# Python code to demonstrate the working of
50+
# fabs() and factorial()
51+
52+
a = -10
53+
b= 5
54+
55+
# returning the absolute value.
56+
print ("The absolute value of -10 is : ", end="")
57+
print (math.fabs(a))
58+
59+
# returning the factorial of 5
60+
print ("The factorial of 5 is : ", end="")
61+
print (math.factorial(b))
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#Python | random.sample() function
2+
3+
import random
4+
5+
print ("The random value from random.seed(10) is : ", end="")
6+
print (random.seed(10))
7+
#If we wanted a random integer, we can use the randint function
8+
#Randint accepts two parameters: a lowest and a highest number.
9+
#Generate integers between 1,5. The first value should be less than the second.
10+
print ("The random integer value from 10 to 100 is : ", end="")
11+
print (random.randint(10,100))
12+
13+
#If you want a larger number, you can multiply it.
14+
#For example, a random number between 0 and 100:
15+
print ("The random value of random function is : ", end="")
16+
print (random.random()*20)
17+
18+
# Python code to demonstrate the working of
19+
# randrange()
20+
print ("The random range of 1000 is : ", end="")
21+
print (random.randrange(1000))
22+
23+
print ("The random range of 10 to 100 by skipping 2 is : ", end="")
24+
print (random.randrange(10,100,2))
25+
26+
a=[1,2,9,'c','e',1.1]
27+
print ("list a value is ",a)
28+
print ("The list a value after random.shuffle function is : ", end="")
29+
random.shuffle(a)
30+
print (a)

0 commit comments

Comments
 (0)