forked from moehuster/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.py
More file actions
35 lines (28 loc) · 672 Bytes
/
Copy pathstring.py
File metadata and controls
35 lines (28 loc) · 672 Bytes
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
### String Processing
# String literals
s1 = "Rixner's funny"
s2 = 'Warren wears nice ties!'
s3 = ' T-shirts!'
#print s1, s2
#print s3
# Combining strings
s4 = "Warren" + ' and ' + "Rixner" + ' are nuts!'
#print s4
# Characters and slices
print s1[-1]
print len(s1)
print s1[0:6] + s2[6:]
print s2[:13] + s1[9:] + s3
# Converting strings
s5 = str(375)
print s5
i1 = int(s5[1:])
print i1 + 30
# convert xx.yy to xx dollars and yy cents
def convert(val):
dollars = int(val)
cents = int(100*(val-dollars))
return str(dollars) + " dollars and " + str(cents) + " cents"
# Test
print (convert(11.23))
print (convert(11.20))