我正在尝试编写一个函数来查找给定位长度的有符号/无符号最大值/最小值。但是每次我执行函数时都会出错,这是我的代码
#function to find max and min number of both signed and unsigned bit values
def minmax (n) :
for numbers in n :
unsignedmax = (2**n)-1
unsignedmin = 0
signedmax = 2**(n-1)-1
signedmin = -2**(n-1)
print "number ", "unsigned ", "signed"
#Main
bitlist = [2, 3, 8, 10, 16, 20, 32]
minmax(bitlist)
错误是
Traceback (most recent call last):
File "C:/Users/Issac94/Documents/Python Files/sanchez-hw07b.py", line 23, in <module>
minmax(bitlist)
File "C:/Users/Issac94/Documents/Python Files/sanchez-hw07b.py", line 6, in minmax
unsignedmax = (2**n)-1
TypeError: unsupported operand type(s) for ** or pow(): 'int' and 'list'
>>>
我还没有写完,但是运行它以确保逻辑部分没有错误,但是在尝试查找值时出现了一个错误。有没有办法插入 int() 或类似的东西,将数字视为整数类型而不是我假设正在发生的类型列表?