+ 4

Can someone more clearly explain what accumulate is? Say if there is 10 variables, and you accumulate with range(8), does it take the first 8 integers/strings or any random 8 integer/string?

Accumulate

25th Sep 2016, 11:19 AM
Gideon Tay Yee Chuen
Gideon Tay Yee Chuen - avatar
4 Answers
+ 1
It returns the sum of all previous elements and the current one, for example, if you have: print(list(accumulate([5,4,22]))) then it will print: [5,9,31] equivalent to [5,5+4,5+4+22]
19th Jul 2018, 7:45 PM
George Ciuclea
George Ciuclea - avatar
0
George Ciuclea you are right regarding the logic of accumulate method. Doc to refer: https://docs.python.org/3/library/itertools.html#itertools.accumulate
30th Apr 2019, 10:14 AM
Noopur
Noopur - avatar
- 1
i still do'nt get it
7th Nov 2016, 8:21 PM
turbofighter
turbofighter - avatar
- 9
for str_employee in range(5): def Name (): strName = input ("Enter your name: ") return strName def hoursworked (): strhours = input ("Enter Total Hours Worked: ") flthours = float(strhours) return flthours def wagerate (): strwage = input ("Enter Wage Rate:
quot;) fltwage = float(strwage) return fltwage currentUser = Name() currentSal = (hoursworked () * wagerate ()) fltpercent_08 = float (.08) fltpercent_20 = float (.20) fltfedtax = (currentSal * fltpercent_20) fltstatetax = (currentSal * fltpercent_08) print ("") print ("Your Federal Tax is:
quot;, fltfedtax) print ("Your State Tax is:
quot;, fltstatetax) print ("") sum = fltfedtax for fltstatetax in range (0): sum = fltfedtax + fltfedtax sum2 = fltstatetax for fltstatetax in range (0): sum2 = fltstatetax + fltstatetax print ("") print ("Total Taxes") print ("Total Federal Tax is:
quot;, sum) print ("Total State Tax is:
quot;, sum2)
25th Sep 2016, 12:29 PM
Gurtej Singh
Gurtej Singh - avatar