#๐ help
50 messages ยท Page 1 of 1 (latest)
@slow zodiac
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Wdym by prefix sum
In computer science, the prefix sum, cumulative sum, inclusive scan, or simply scan of a sequence of numbers x0, x1, x2, ... is a second sequence of numbers y0, y1, y2, ..., the sums of prefixes (running totals) of the input sequence:
y0 = x0
y1 = x0 + x1
y2 = x0 + x1+ x2
...
For instance, the prefix sums of the natural numbers are the triangul...
by itself, it's not too interesting (the i'th prefix sum of some sequence is just the sum of the first i elements)
where did you see it?
Prefix sum aka cumulative sum aka cumsum
Already searched it lol
ye
i need python code of it
can u help
can u give me a python code of it?
i need for my exam
we don't really code for people here, but it shouldn't be too hard given you understand the definition
i'm not good at understanding explainations ๐ญ
!rule 8
8. Do not help with ongoing exams. When helping with homework, help people learn how to do the assignment without doing it for them.
i need help to understand how prefix sum work bro?
bc my teacher said prefix sum will appeared in the exam
so i need help understanding it
well there are indeed code examples on that wiki page. did your teacher not teeach it to you at all?
i need to learn python for transfer exam
but my school teaches js
thats the problem
so you need to learn python. sounds like you need to start with the basics unless you have some python knowledge already
i got some alrd
but it jst some basics
so does it make sense to you that a prefix sum is the cumulative sum of all elements in a list at each index of the list?
list [1, 1, 1, 1, 1] prefix sum [1, 2, 3, 4, 5]
can explain it with code, like just the main part of it
english is not my mother tongue
so im rlly bad
well honestly the code to explain it is basically the exact answer to the exam question so lets try a different approach. Are you familiar with for loops?
ye
i think
so with the list like [1, 2, 3, 4, 5] how would you itterate over it and print out each number in the list?
for number in numbers:
print(number)
Hey @slow zodiac!
Add a py after the three backticks.
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
ok, and you wrote that yourself? cool. so now what would you do if you wanted to add them all together?
i think ima add a loop?
or maybe a sum
so you can do it in the same loop
and say you have
x = 1
print(x)```
how would you add 5 to x so that it prints out as `6`?
x = 1
x += 5
print(x)
Hey @slow zodiac!
Make sure there are no spaces between the back ticks and py.
Here is an example of how it should look:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
Ok now take that knowledge and apply it to the loop for the list of numbers
i still dont understand can u give me a proper python code for it like an example
numlist = [1, 2, 3, 4, 5]
sum = 0
for number in numlist:
sum += number
print(sum)```
aight tysm
!close
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.