0

Got a while loop and need to implement a counting method?

I got a list of prime numbers from a min to a max, but i dont know how to implement a way to count them.

13th Aug 2020, 9:25 AM
Dignity Digs
11 ответов
+ 3
What do you mean by count? if you want the number of primes that you have in your list then you can just use the len() function on the list. primes = [2, 3, 5, 7, 11] cnt = len(primes) # cnt = 5 If you want to sum the primes together in the list you can similarly use the sum function on the list. cnt = sum(primes) # cnt = 28
13th Aug 2020, 9:32 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Dignity Digs I hope you understood your own code
13th Aug 2020, 9:44 AM
Namit Jain
Namit Jain - avatar
13th Aug 2020, 10:28 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Add them to a list and then count the items 🤠
14th Aug 2020, 9:04 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
Its public sorry and thanks for the help.
13th Aug 2020, 9:34 AM
Dignity Digs
13th Aug 2020, 9:39 AM
Namit Jain
Namit Jain - avatar
+ 1
Holy you just made that easy thanks mate. Also thats not entirely my code its a mix of stuff i got off the internet ahaha.
13th Aug 2020, 9:40 AM
Dignity Digs
+ 1
Yeah i tried but i end up overthinking it but thanks for your help.
13th Aug 2020, 9:43 AM
Dignity Digs
0
print(len(listName))
13th Aug 2020, 9:27 AM
Namit Jain
Namit Jain - avatar
0
Namit but idk how to assign a list to an output, look at my code bits called lab
13th Aug 2020, 9:30 AM
Dignity Digs
0
Dignity Digs Just a small advice: If you want to solve some problem then first try your best and then think of getting solution from internet
13th Aug 2020, 9:42 AM
Namit Jain
Namit Jain - avatar