Oct-14-2019, 03:24 AM
I hope my title wasn't too long. I have code to make a random string of numbers; 0 or 1. I want it to count and print how many times 1 appears in the string of numbers. This is what i have so far:
I feel that i have no idea if its actually counting whether its 1 or not. I'm kind of figuring there's a better way to do what I'm trying to accomplish. Thanks for helping!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import random def Rand(Start, end, num): res = [ ] for j in range (num): res.append(random.randint(start, end)) return res num = 1000 start = 0 end = 1 pie = (Rand(start, end, num)) def count(lst): return sum (lst) lst = pie print (count(lst)) |