Commit 5f561671 authored by wongkai junttajit's avatar wongkai junttajit

ส่งการบ้าน assignment และคะแนนพิเศษ ggwp

parent 1e791784
#pos=input("pos :")
#neg=input("neg :")
#1.homework def value(v,pos,neg):
def value1(v,pos,neg):
sign = -1 if v[0] == 1 else 1 sign = -1 if v[0] == 1 else 1
return sign * sum([v[i] * 2 ** (pos - i) for i in range(1, pos+neg+1)]) return sign * sum([v[i] * 2 ** (pos - i) for i in range(1, pos+neg+1)])
v=[0,0,0,0,1,0,1,1] v=[0,0,0,0,1,0,1,1]
print(value1(v,4,3)) print(value(v,4,3))
#2.คะแนนพิเศษ
def value2(v, pos, neg): def values(v, pos, neg):
ang= list(map(int,v)) ang= list(map(int,v))
sign = -1 if ang[0] == 1 else 1 sign = -1 if ang[0] == 1 else 1
return sign * sum([ang[i] * 2 ** (pos - i) for i in range(1, pos + neg + 1)]) return sign * sum([ang[i] * 2 ** (pos - i) for i in range(1, pos + neg + 1)])
print(value2('000100100', 5, 3)) print(values('000100100', 5, 3))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment