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.
11 Réponses
+ 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
+ 2
Dignity Digs I hope you understood your own code
+ 2
Add them to a list and then count the items 🤠
+ 1
Its public sorry and thanks for the help.
+ 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.
+ 1
Yeah i tried but i end up overthinking it but thanks for your help.
0
print(len(listName))
0
Namit but idk how to assign a list to an output, look at my code bits called lab
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