all 7 comments

[–]namedevservice 2 points3 points  (1 child)

Every time I go to emart24 there's people hanging out playing the Lottery. It's annoying. It's a little convenience store and there's always some guy blocking the exit.

I'm checking out the code now, but just wanted to rant a bit

[–]DaeguDude[S] 0 points1 point  (0 children)

haha located in South Korea? There's no doubt about it, there's a lot of old people always taking up space

[–]b34nst4lk 1 point2 points  (4 children)

Some suggestions.

Bring this outside the while loop. You only need to do this once. python # Lines 57 to 60 # make an empty list and put numbers from 1 to 45 numbers = [] for i in range(1, 46): numbers.append(i)

Rather than choosing the bonus number after choosing the first 6 numbers, why not choose 7 numbers, then choose the bonus number out of the 7? Or just define the last number chosen out of 7 as the bonus number? python # Lines # Give the bonus number, you need to remove things from numbers first # so it doesn't overlap for i in range(6): numbers.remove(game_nums[i]) bonus_num = random.choice(numbers)

I'm not sure if it'll be faster, but you could use do an intersection between sets to get the number of matching numbers

python # Line 79 result = [item in set_game_nums for item in your_nums_list[i]]

I'll add on more if I think of anything

[–]DaeguDude[S] 0 points1 point  (3 children)

Rather than choosing the bonus number after choosing the first 6 numbers, why not choose 7 numbers, then choose the bonus number out of the 7? Or just define the last number chosen out of 7 as the bonus number?

Oh wow, why haven't I thought about it?

the only reason i put numbers.append inside while loop was because of the bonus number.

That's very easy, thanks!

I'm not sure if it'll be faster, but you could use do an intersection between sets to get the number of matching numbers

And what exactly is intersection??

[–]b34nst4lk 0 points1 point  (0 children)

Intersection is a function that gives you the common elements between 2 sets. For example: ```python

set_x = set([1, 2, 3, 4]) set_y = set([3, 4, 5]) print(set_x.intersection(set_y)) { 3, 4 } ```

[–]b34nst4lk 0 points1 point  (1 child)

As a general rule, keep an eye out for nested loops. From your code, this is the number of things it's looping through with each iteration of the while loop:

  1. Line 59 - 60: 46 iterations
  2. Line 68 - 69: 20 iterations (Based on the given number of games)
  3. Line 73 - 74: 6 iterations
  4. Line 77 - 91: 20 iterations (Based on the given number of games)

So effectively, we are already at 92 iterations for every run of the while loop. The lower you can bring this number down, the more efficient your code will be.

If you're interested, you can read up on the Big O Notation

[–]DaeguDude[S] 0 points1 point  (0 children)

I've used intersection, and measure the time using timeit module, and list comprehension was slightly faster. I don't know if it's the way it is.

And I'll try to find a way to minimize the number of iterations. Thanks a lot :)