Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am trying to make a hexadecimal convertor. The program keep telling me there is something wrong with my math operators, but I believe the
I am trying to make a hexadecimal convertor. The program keep telling me there is something wrong with my math operators, but I believe the problem is somewhere in the constructor. The tester program gives me a score of 63/100. Any advice on where I am going wrong would be great.
class Hexadecimal: def init_ _(self, decimal-"1128") if type (decimal) is int: if decimal 0: self. decimal=decimal else: raise ValueError ("Must be greater than zero." elif type (decimal) is list: zaise ValueEzror ("Cannot enter lists.") elif type (decimal) is float: decimal = int (decimal) if decimal 0: self. decimal decimal else: raise ValueError ("Cannot have negative floats.") elif type (decimal) is str: try: if decimal not in ["A", "B",C","D", "E", "F: decimal except ValueError as Ex: float (decimal) raise ValueError ("Cannot convert string to float.") else: self. decimalint (decimal) elif type (decimal) is str:' values = {'A': 10, 'B' :11, decimaldecimal.upper ) h values [] for letter in decimal: 'C' :12, "D":13, 'E' :14, 'F' :15) if letter in values: h_values.append (valuesietter]) else: raise ValueErro "Invalid Hexadecimal") class Hexadecimal: def init_ _(self, decimal-"1128") if type (decimal) is int: if decimal 0: self. decimal=decimal else: raise ValueError ("Must be greater than zero." elif type (decimal) is list: zaise ValueEzror ("Cannot enter lists.") elif type (decimal) is float: decimal = int (decimal) if decimal 0: self. decimal decimal else: raise ValueError ("Cannot have negative floats.") elif type (decimal) is str: try: if decimal not in ["A", "B",C","D", "E", "F: decimal except ValueError as Ex: float (decimal) raise ValueError ("Cannot convert string to float.") else: self. decimalint (decimal) elif type (decimal) is str:' values = {'A': 10, 'B' :11, decimaldecimal.upper ) h values [] for letter in decimal: 'C' :12, "D":13, 'E' :14, 'F' :15) if letter in values: h_values.append (valuesietter]) else: raise ValueErro "Invalid Hexadecimal")Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started