Skip to content

Commit cb42249

Browse files
committed
add string formatting lab project
1 parent 0c13840 commit cb42249

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# String format lab execises from session-03
2+
# produce 'file_002 : 123.46, 1e+04'
3+
4+
import random
5+
import string
6+
import sys
7+
import os
8+
import math
9+
10+
#passnum function to pass the 3 numbers
11+
def passnum(x,y,z):
12+
print("The first 3 numbers are: {:d}, {:d}, {:d}".format(x,y,z))
13+
n = ('{:d}{:d}{:d}'.format(x,y,z))
14+
return n
15+
16+
#call the function
17+
n=passnum(x=7,y=8,z=9)
18+
19+
# Convert the returned value to an integer
20+
n = int(n)
21+
f1 = '{:.4f}'.format(.4567).lstrip('0')
22+
23+
# Convert to float
24+
f = float(f1)
25+
26+
m = ('{:d}{:.4f}'.format(n,f).lstrip('0'))
27+
28+
# Convert to float
29+
m = float(m)
30+
# This was the only way for now I could get rid of the leading zero
31+
m = (m/10)+0.41103
32+
33+
strg = (2,m,10000)
34+
print("Change this............",strg)
35+
36+
a = ('{:d}'.format(strg[0]))
37+
b = ('{:05.2f}'.format(strg[1]))
38+
# Format the last value as an exponent
39+
c = ('{:01.0e}'.format(strg[2]))
40+
41+
print("To this................ file_00{} : {},".format(a,b),c,'\n')
42+

0 commit comments

Comments
 (0)