예제 #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>Assume exactly one bit is incorrect.</p>' + \
         'Indicate the incorrect bit ' + \
         'using <b>' + parity_string  + '</b> parity:'

        # generate list of radio buttons with
        # the bit specified by answer set
        indexes = range(1, len(self.code_word) + 1)  # one-relative
        radio_buttons = []
        for i in indexes:
            is_set = answer['incorrect_bit'] == str(i)
            radio_buttons.append(
                html_util.get_radio_button('incorrect_bit', str(i), is_set))

        # generate table containing radio buttons
        html += '<center>'
        html += html_util.get_table([indexes, self.code_word, radio_buttons],
                                    'id="hamming_table"')
        html += '</center>'

        return html
예제 #3
0
	def get_html(self,answer):
		# generate question description
		if self.parity == 0:
			parity_string = 'even'
		else:
			parity_string = 'odd'
		html = '<p>Assume exactly one bit is incorrect.</p>' + \
		 'Indicate the incorrect bit ' + \
		 'using <b>' + parity_string  + '</b> parity:'

		# generate list of radio buttons with
		# the bit specified by answer set
		indexes = range(1,len(self.code_word)+1) # one-relative
		radio_buttons = []
		for i in indexes:
			is_set = answer['incorrect_bit'] == str(i)
			radio_buttons.append(html_util.get_radio_button(
			 'incorrect_bit',str(i),is_set))

		# generate table containing radio buttons
		html += '<center>'
		html += html_util.get_table(
		 [indexes,self.code_word,radio_buttons],'id="hamming_table"')
		html += '</center>'

		return html
예제 #4
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
예제 #5
0
	def get_html(self, answer):		
		html = "<div class=\"container\">"
		html += "<p>Use a <b>caesar</b> cipher with key " + str(self.key)  + " to encrypt the plain text.</p>"
		topArray = ["Plain text"]
		bottomArray = ["Cipher text"]
		
		#Load the Plain text into a list
		for char in self.plaintext:
			topArray.append(str(char))
			
		#Load the cipher text into the bottom array
		for char in self.ciphertext:
			bottomArray.append(str(char))
		
		#Replace hotspot positions with text boxes
		i = 0
		for pos in self.hotspots:
			if answer['answer'] == None: #DR1
				bottomArray[pos+1] = html_util.get_text('answer', '', 1) #DR2
			else:
				bottomArray[pos+1] = html_util.get_text('answer', answer['answer'][i], 1) #DR3 #DR4
				i=i+1
		
		tableArray = [topArray, bottomArray]
		
		html += html_util.get_table(tableArray, "class=\"center_table\"")

		return html + "</div>"
예제 #6
0
	def get_html(self,answer):
		j = 0
		html = "<style type='text/css'>"
		html += html_util.make_css_borders(1)
		html += "</style>"
		html += "<p>Use a <b>caesar</b> cipher with key %d to encrypt the plain text.</p><center>" % self.key
		plaintext_list = [("plain text", "right")]
		for i in range(0, len(self.plaintext)):
			plaintext_list.append(("<tt>" + self.plaintext[i] + "</tt>", "left_border center")) # DR1
		ciphertext_list = [("cipher text", "top_border right")]
		for i in range(0, len(self.ciphertext)):
			if(i in self.hotspots):
				ciphertext_list.append(("<tt>" + html_util.get_text("char_%i" % j, '' if answer['char_%i' % j] is None else answer['char_%i' % j]) + "</tt>", "left_border top_border")) # DR2, DR3, DR4
				j += 1
			else:
				ciphertext_list.append(("<tt>" + self.ciphertext[i] + "</tt>", "left_border top_border")) # DR 5
		html += html_util.get_table([plaintext_list, ciphertext_list], "cellspacing=0 cellpadding=3")
		html += "</center>"	

		return html	
import html_util

print '''<html>
<head>
<title>html_util.get_table() - no borders</title>
</head>
<body>
''' + \
html_util.get_table([['a','b'],['c','d']]) + \
'''
</body>
</html>
'''
import html_util

print '''<html>
<head>
<title>html_util.get_table() - with border</title>
<style type='text/css'>''' + \
html_util.make_css_borders(1,'my_id_string') + \
'''
</style>
</head>
<body>
''' + \
html_util.get_table([['a','b'],['c','d']],'id="my_id_string"') + \
'''
</body>
</html>
'''
import html_util

print '''<html>
<head>
<title>html_util.get_table() - with selective 3px border</title>
<style type='text/css'>''' + \
html_util.make_css_borders(3) + \
'''
</style>
</head>
<body>
''' + \
html_util.get_table([
 ['','9','8'],
 ['','','3'],
 [('1','top_border'),('0','top_border'),('1','top_border')]
],'cellspacing=0') + \
'''
</body>
</html>
'''
예제 #10
0
import html_util

print '''<html>
<head>
<title>html_util.get_table() - with selective 3px border</title>
<style type='text/css'>''' + \
html_util.make_css_borders(3) + \
'''
</style>
</head>
<body>
''' + \
html_util.get_table([
    ['','9','8'],
    ['','','3'],
    [('1','top_border'),('0','top_border'),('1','top_border')]
],'cellspacing=0') + \
'''
</body>
</html>
'''