← Back to all posts
##### Can someone help me with my activity?

Write a Python program that ask the user to enter a maximum number in lotto and automatically generates six random numbers (from 1 to 'num') and comment the formula for display sorted in ascending order and display only the numbers of combination for the lottery game.The program will need to make sure that each number is unique; the same number cannot come twice in the selection of six selected numbers.

this was the question that's given to me i've been coding wrong all the time

Answered by Bookie0 (6267) [earned 5 cycles]
hotnewtop
Bookie0 (6267)

Can you share your code with us? What have you tried already? What's causing the problem? What do you think could help solve it?

We can't just give you the code, but we can help you with it. First, you'll need an input to ask the user to enter a number, then you can use random.randrange() to get a random number, as well as conditionals to determine if the user has already been picked. Or with sample() you can get unique numbers as well. Then you can add each of those numbers in a list, and use sort() to show them in ascending order.

ErelDomingo (4)

@Bookie0 print("Enter max value: ", end="")
n = int(input())
r = 6
fact = i = 1
while i<=n:
fact = i * fact
i += 1

numerator = fact
sub = n-r
fact = i = 1

while i<=sub:
fact = i * fact
i += 1

denominator = fact
fact = i = 1
while i<=r:
fact = i * fact
i += 1

denominator = fact * denominator
comb = numerator/denominator

hi this is one of my classmates code, what can i do so we would have different codes?

Bookie0 (6267)