Search code examples
pythonprintingnumbersautooverlapping

How can I print 6 numbers in ascending order without randomly overlapping the numbers?


Sharing Lotto, the largest lottery in Korea, is conducted by selecting 6 different numbers from 1 to 45. The number of sharing lotto can be selected by the buyer himself, but it can also be selected in an "automatic" way that is left to the machine. Write a program that meets the following conditions so that you can participate in the Sharing Lotto in an 'automatic' manner.

Conditions:

  1. Creating a Function
  2. Return a list of six different integers from 1 to 45 as elements
  3. Returned lists are sorted in ascending order
  4. Print the returned list on the screen

Example of 10 iterations of a function that satisfies a condition: enter image description here

What code should I use to program like this?

umm guys, i want code. i have not error guys


Solution

  • 
    import random
    ans = []
    
    while len(ans)<6 :
      x = random.randrange(0,45,1)
      if x in ans:
        pass
      else:
        ans.append(x)
    ans.sort()
    print(ans)
    
    

    @Aiden this should work, turns out maybe you are not allowed to use numpy