The Enemy of the Good (eideteker) wrote,
The Enemy of the Good
eideteker

  • Mood:
  • Music:

Yay, I made a program that writes an HTML file!

I wrote a program that converts a given base 10 whole number into a base-n number. Then, to automate the QA, I had it print a table of values. For Ss & Gs, I decided to try outputting the result to an HTML file containing tables.

It's crude, but here's the (uncommented) program:

def powercheck(b, x):
    n = 0
    while b*(b**n) <= x:
        n = n + 1
    return n

def dec2base(b, x):
    y = ""
    z = powercheck(b, x)
    while z > 0:
        n = 1
        while n < b:
            if x == n * b**z:
                y = y + str(n) + '0'*z
                return int(y)
            else:
                n = n + 1
        if x > b**z:
            c = x/(b**z)
            y = y + str(c)
            x = x - c*(b**z)
        else:
            y = y + '0'
        z = z - 1
    y = y + str(x/(b**z))
    return int(y)
    
def QAthis(b):
    i = 1
    l = 0
    f.write("<table border=1>\n<tr><td colspan=10><b>" + str(b) + "</b></td></tr>\n")
    while l < 10:
        w = 0
	f.write("<tr>")
        while w < 10:
            txt = "<td>" + str(dec2base(b, i)) + "</td>\n"
            w = w + 1
            i = i + 1
            f.write(txt)
        l = l + 1
        f.write("</tr>")
    f.write("</table>")

f = open("basestoten.htm", 'w')
b = 2
while b <= 10:
    QAthis(b)
    b = b + 1
f.close()

And here's the output:

2
1 10 11 100 101 110 111 1000 1001 1010
1011 1100 1101 1110 1111 10000 10001 10010 10011 10100
10101 10110 10111 11000 11001 11010 11011 11100 11101 11110
11111 100000 100001 100010 100011 100100 100101 100110 100111 101000
101001 101010 101011 101100 101101 101110 101111 110000 110001 110010
110011 110100 110101 110110 110111 111000 111001 111010 111011 111100
111101 111110 111111 1000000 1000001 1000010 1000011 1000100 1000101 1000110
1000111 1001000 1001001 1001010 1001011 1001100 1001101 1001110 1001111 1010000
1010001 1010010 1010011 1010100 1010101 1010110 1010111 1011000 1011001 1011010
1011011 1011100 1011101 1011110 1011111 1100000 1100001 1100010 1100011 1100100
3
1 2 10 11 12 20 21 22 100 101
102 110 111 112 120 121 122 200 201 202
210 211 212 220 221 222 1000 1001 1002 1010
1011 1012 1020 1021 1022 1100 1101 1102 1110 1111
1112 1120 1121 1122 1200 1201 1202 1210 1211 1212
1220 1221 1222 2000 2001 2002 2010 2011 2012 2020
2021 2022 2100 2101 2102 2110 2111 2112 2120 2121
2122 2200 2201 2202 2210 2211 2212 2220 2221 2222
10000 10001 10002 10010 10011 10012 10020 10021 10022 10100
10101 10102 10110 10111 10112 10120 10121 10122 10200 10201
4
1 2 3 10 11 12 13 20 21 22
23 30 31 32 33 100 101 102 103 110
111 112 113 120 121 122 123 130 131 132
133 200 201 202 203 210 211 212 213 220
221 222 223 230 231 232 233 300 301 302
303 310 311 312 313 320 321 322 323 330
331 332 333 1000 1001 1002 1003 1010 1011 1012
1013 1020 1021 1022 1023 1030 1031 1032 1033 1100
1101 1102 1103 1110 1111 1112 1113 1120 1121 1122
1123 1130 1131 1132 1133 1200 1201 1202 1203 1210
5
1 2 3 4 10 11 12 13 14 20
21 22 23 24 30 31 32 33 34 40
41 42 43 44 100 101 102 103 104 110
111 112 113 114 120 121 122 123 124 130
131 132 133 134 140 141 142 143 144 200
201 202 203 204 210 211 212 213 214 220
221 222 223 224 230 231 232 233 234 240
241 242 243 244 300 301 302 303 304 310
311 312 313 314 320 321 322 323 324 330
331 332 333 334 340 341 342 343 344 400
6
1 2 3 4 5 10 11 12 13 14
15 20 21 22 23 24 25 30 31 32
33 34 35 40 41 42 43 44 45 50
51 52 53 54 55 100 101 102 103 104
105 110 111 112 113 114 115 120 121 122
123 124 125 130 131 132 133 134 135 140
141 142 143 144 145 150 151 152 153 154
155 200 201 202 203 204 205 210 211 212
213 214 215 220 221 222 223 224 225 230
231 232 233 234 235 240 241 242 243 244
7
1 2 3 4 5 6 10 11 12 13
14 15 16 20 21 22 23 24 25 26
30 31 32 33 34 35 36 40 41 42
43 44 45 46 50 51 52 53 54 55
56 60 61 62 63 64 65 66 100 101
102 103 104 105 106 110 111 112 113 114
115 116 120 121 122 123 124 125 126 130
131 132 133 134 135 136 140 141 142 143
144 145 146 150 151 152 153 154 155 156
160 161 162 163 164 165 166 200 201 202
8
1 2 3 4 5 6 7 10 11 12
13 14 15 16 17 20 21 22 23 24
25 26 27 30 31 32 33 34 35 36
37 40 41 42 43 44 45 46 47 50
51 52 53 54 55 56 57 60 61 62
63 64 65 66 67 70 71 72 73 74
75 76 77 100 101 102 103 104 105 106
107 110 111 112 113 114 115 116 117 120
121 122 123 124 125 126 127 130 131 132
133 134 135 136 137 140 141 142 143 144
9
1 2 3 4 5 6 7 8 10 11
12 13 14 15 16 17 18 20 21 22
23 24 25 26 27 28 30 31 32 33
34 35 36 37 38 40 41 42 43 44
45 46 47 48 50 51 52 53 54 55
56 57 58 60 61 62 63 64 65 66
67 68 70 71 72 73 74 75 76 77
78 80 81 82 83 84 85 86 87 88
100 101 102 103 104 105 106 107 108 110
111 112 113 114 115 116 117 118 120 121
10
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

PS: I know I code as smoothly as a fist to the jaw, so any suggestions at streamlining are accepted. Thanks!

Tags: python
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 1 comment