示例#1
0
	def get_html(self,answer):
		# generate question description
		if self.parity == 0:
			parity_string = 'even'
		else:
			parity_string = 'odd'
		html = "<p>Fill in the bits for a valid Hamming code " + \
		 'using <b>' + parity_string  + '</b> parity:</p>'

		# generate a list of selects with bits specified by answer
		# bits = list of len(code_word) items where bits[i]:
		#	code_word[i] if code_word[i] in [0,1]
		#	a select box if code_word[i] is None
		indexes = range(1,len(self.code_word)+1) # one-relative
		bits = []
		for i,bit in enumerate(self.code_word,1):
			if bit == None:
				name = 'bit_' + str(i)
				bit = html_util.get_select(
				 name,['','0','1'],answer[name])
			bits.append(bit)

		# generate table containing select lists
		html += '<center>'
		html += html_util.get_table([indexes,bits],'id="hamming_table"')
		html += '</center>'

		return html
示例#2
0
    def get_html(self, answer):
        # generate question description
        if self.parity == 0:
            parity_string = 'even'
        else:
            parity_string = 'odd'
        html = "<p>Fill in the bits for a valid Hamming code " + \
         'using <b>' + parity_string  + '</b> parity:</p>'

        # generate a list of selects with bits specified by answer
        # bits = list of len(code_word) items where bits[i]:
        #	code_word[i] if code_word[i] in [0,1]
        #	a select box if code_word[i] is None
        indexes = range(1, len(self.code_word) + 1)  # one-relative
        bits = []
        for i, bit in enumerate(self.code_word, 1):
            if bit == None:
                name = 'bit_' + str(i)
                bit = html_util.get_select(name, ['', '0', '1'], answer[name])
            bits.append(bit)

        # generate table containing select lists
        html += '<center>'
        html += html_util.get_table([indexes, bits], 'id="hamming_table"')
        html += '</center>'

        return html
示例#3
0
import html_util

print '''<html>
<head><title>html_util test output</title></head>
<body>
'''
print 'visible initial selection ' +\
 html_util.get_select('text0',['0','1'],'1') + \
 '<p>' + \
 'empty initial selection ' + html_util.get_select('text1',['','0','1'],'')

print '''
</body>
</html>
'''