Skip to content

Commit 123a9da

Browse files
Add files via upload
1 parent 8ee1e94 commit 123a9da

8 files changed

+188
-0
lines changed

builtin_string_functions_6.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Fri Apr 24 19:56:39 2020
4+
5+
@author: HP
6+
"""
7+
8+
# String fucntions
9+
10+
#1. Join
11+
12+
print("*".join("Hello"))
13+
14+
print("***".join("Hello"))
15+
16+
print("$$".join(["trial","hello"])) # When Joined with list
17+
18+
print("$$".join(("trial","hello","new"))) #when joined with tuple
19+
20+
#print("$$".join((123,"hello","new"))) # sequence must contain string otherwise python will give error
21+
22+
#2. split
23+
24+
print("I love python".split())
25+
# or
26+
print("I Love python".split(" "))
27+
28+
print("I love python".split("o")) # Given string is divided from positon contained "o"
29+
30+
31+
#3. Replace
32+
print("I love python".replace("python","Programming"))
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Apr 21 13:06:22 2020
4+
5+
@author: HP
6+
"""
7+
#importing modules and its functions
8+
#example 1
9+
import tempconversion_1
10+
print(tempconversion_1.to_centigrade(98.6))
11+
12+
#example 2
13+
# giving alias name
14+
import tempconversion_1 as tc
15+
print(tc.to_centigrade(98.6))
16+
17+
#example 3
18+
#to import single object
19+
from math import pi
20+
print(pi)
21+
22+
#example 4
23+
# to import multiple objects
24+
from math import sqrt,pow
25+
from tempconversion_1 import to_centigrade
26+
print(tempconversion_1.to_centigrade(98.6))
27+
print(sqrt(25))
28+
print(pow(3,3))
29+
print
30+
#example 5
31+
# to import all modules
32+
from math import *
33+
from tempconversion_1 import *
34+
print(tempconversion_1.to_centigrade(98.6))
35+
print(tempconversion_1.to_fahrenhit(98.6))
36+
print(sqrt(25))
37+
print(pow(3,3))
38+
39+
40+
#Example 6
41+
from tempconversion_1 import *
42+
print(FREEZZING_C)
43+
FREEZZING_C=17.5
44+
print(FREEZZING_C)

pthon_bulitin_functions_4.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Fri Apr 24 19:44:32 2020
4+
5+
@author: HP
6+
"""
7+
8+
# Python bulit in functions
9+
10+
print(abs(-12))
11+
12+
print(divmod(7,2)) # Take two numbers as complex and returns a pair of numbers consisiting of quotient and reminder
13+
14+
print(sum([2,3,4]))
15+
16+
print(max(3,5))
17+
18+
print(max([3,5,9],[7]))#maximum of two list arguments returned--list that begins with a higher value is returned
19+
20+
print(min(3,5))
21+
22+
print(min([3,5,9],[7]))
23+
24+
print(oct(24)) # return octal string for given numbers
25+
26+
print(hex(24)) #return hex string for given numbers

radom functions_7.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sat Apr 25 13:34:56 2020
4+
5+
@author: HP
6+
"""
7+
8+
import random
9+
print(random.random()) #The output generated is b/w range[0.0,1.0]
10+
11+
print(random.random()*(35-15)+15) # The output generated floating point number b/w 15 to 35
12+
13+
print(random.randint(15,35)) # the output generated is integer b/w range 15 to 35
14+
15+
print(random.uniform(11,55)) # generating floating point random number in the range 11 to 55
16+
17+
18+
print(random.randrange(23,47,3))#generate a random integer in the range 23 to 47 with step 3

tempconversion_1.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Apr 21 12:18:56 2020
4+
5+
@author: HP
6+
"""
7+
"""Conversion functions between fahrehit and centrigrade"""
8+
9+
10+
#Functions
11+
def to_centigrade(x):
12+
"""Returns :x converted to centigrade"""
13+
return 5*(x-32)/9.0
14+
15+
def to_fahrenhit(x):
16+
"""Returns :x converted to fahreheit"""
17+
return 9*x/5.0+32
18+
19+
#constants
20+
FREEZZING_C=0.0
21+
FREEZING_F=32.0

use of built in functions_5.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Fri Apr 24 19:52:25 2020
4+
5+
@author: HP
6+
"""
7+
8+
#input a number and converts ito nearest integer using
9+
# two different built in functions. It also disaplay the given number
10+
# rounded off to 3 places after decimal.
11+
12+
num=float(input("enter a real number:"))
13+
tnum=int(num)
14+
rnum=round(num)
15+
print(tnum,"and",rnum)
16+
rnum2=round(num,3)
17+
print(num,"rounded off to 3 places after decimal is",rnum2)

using modules_2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Apr 21 12:25:50 2020
4+
5+
@author: HP
6+
"""
7+
8+
import tempconversion_1
9+
help(tempconversion_1)
10+
11+

using string modules_8.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sat Apr 25 13:34:56 2020
4+
5+
@author: HP
6+
"""
7+
8+
import string
9+
print(string.ascii_letters)
10+
11+
print(string.digits)
12+
13+
print(string.ascii_uppercase)
14+
15+
print(string.punctuation)
16+
17+
18+
line="this is a simple line\n New line:->"
19+
print(string.capwords(line))

0 commit comments

Comments
 (0)