-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment1.py
More file actions
executable file
·145 lines (108 loc) · 3.4 KB
/
assignment1.py
File metadata and controls
executable file
·145 lines (108 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
__creator__='Kalinga'
import string
import sys
from testmodule.styleformat import heading
#1. Write a program to print the:
#a. Number of lowercase 'a' and "o" in the following sentence.
#Discover, Learning, with, MySimpleClass
def firstTaskLowercaseCount():
print "Calling " + firstTaskLowercaseCount.__name__
str = "Discover, Learning, with, TeachMe"
print "Number of 'a': %d, 'o': %d are there" % (str.count('a'), str.count('o'))
#b. Number of uppercase 'L' and 'N' in the following sentence.
def firstTaskUppercaseCount():
print "\nCalling " + firstTaskUppercaseCount.__name__
str = "Discover, Learning, with, TeachMe"
print "Number of 'L': %d, 'N': %d are there" % (str.count('L'), str.count('N'))
#2. Write a program to remove the following from:
#www.edureka.in
#a. Remove all w' s before and after .edureka.
#b. Remove all lowercase letter before and after .edureka.
def secondTask_a():
print "\nCalling " + secondTask_a.__name__
str = "www.edureka.in"
print str.strip('w')
print sys.argv
def secondTask_b():
print "\nCalling " + secondTask_b.__name__
print "strip() works in removing from leading and trailing end not through out the text"
str = "WWW.http.edureka.IN"
newStr=''
index = str.find(".edureka.")
print index
for i in range(index):
#print i
if (not str[i].islower()):
newStr = newStr + str[i]
print newStr
newStr = newStr + ".edureka."
for i in range(str.find(newStr) + len(newStr), len(str)):
#print i
if (not str[i].islower()):
newStr = newStr + str[i]
str = newStr
print str
#c. Remove all printable characters
def secondTask_c():
print "\nCalling " + secondTask_c.__name__
str = "www.edureka.in"
newStr = ''
for i in range(len(str)):
#print i
if (not str[i] in string.printable):
newStr = newStr + str[i]
str = newStr
print str
#3. Identify the type of numbers:
#a. 0X7AE
def thirdTask_a():
print (type(0X7AE))
#b. 3+4j
def thirdTask_b():
print (type(3+4j))
#c. -01234
def thirdTask_c():
print (type(-01234))
#d. 3.14e-2
def thirdTask_d():
print (type(3.14e-2))
#4. Write a program for String Formatting Operator % which should include the following conversions:
#a. Character
def fourthTask_a():
option = "Y"
print "\nInput option '%c' for Yes" %(option)
#b. Signed decimal integer
def fourthTask_b():
print "Input integer '%i' with sign" % (-456)
#c. Octal integer
def fourthTask_c():
print "Input number '%o' is Octal" % (0345)
#d. Hexadecimal integer (UPPERcase letters)
def fourthTask_d():
print "Input number '%X' is HEX" % (0X12AF5)
#e. Floating point real number
def fourthTask_e():
print "Input number '%f' is a Floating point Real number" % (234.34)
#f. Exponential notation (with lowercase 'e')
def fourthTask_f():
print "Input number '%e' is a Floating point Real number" % (233454.34)
if __name__ =='__main__':
heading("Module 1 Assignments: 1")
firstTaskLowercaseCount()
firstTaskUppercaseCount()
heading("Module 1 Assignments: 2")
secondTask_a()
secondTask_b()
secondTask_c()
heading("Module 1 Assignments: 3")
thirdTask_a()
thirdTask_b()
thirdTask_c()
thirdTask_d()
heading("Module 1 Assignments: 4")
fourthTask_a()
fourthTask_b()
fourthTask_c()
fourthTask_d()
fourthTask_e()
fourthTask_f()