Python add numbers up in loop -
i have list of numbers:
list1 = [33, 11, 42, 53, 12, 67, 74, 34, 78, 10, 23]
what need calculate total amount of numbers in list, divide 360 work out portions of circle. example 32. have done below:
def heading(): heading_loop in range(len(list1)): heading_deg = (360 / len(list1)) return heading_deg
the problem have need have number (heading_deg) append last number everytime runs throught loop. e.g.
run 1: 32 run 2: 64 run 3: 96 run 4: 128
etc etc
any ideas?? @ moment return 32, 11 times.
thanks!!
i'm sorry i've posted answer think wanna different show in code. have if want:
def heading(): result=[] #create void list numbersum=sum(list1) #"calculate total amount of numbers in list" # e.g. if list=[1,1,2] sum(list) return 1+1+2. in range(len(list1)): result.append(((list1[i])/float(numbersum))*360) # calculate portion of circle ("then divide 360 work out portions of circle") #in case if have list a=[250,250] function return 2 angle of 180° #however can return portion of circle in percent e.g. 0.50 half circle 1 whole circle removing "*360" code above return result
if try:
test=heading() print test print sum(test)
the last should print 360°.
Comments
Post a Comment