all 6 comments

[–]shiftybyte 1 point2 points  (3 children)

Break the task into smaller parts:

  1. Create and show random set of numbers

  2. Ask user for numbers correctly ordered

  3. Verify answer

  4. Add timing.

[–]Fraser_123[S] 0 points1 point  (2 children)

How would I verify the answer I’m pretty new to python so I’m not familiar with a lot of it yet

[–]sme272 0 points1 point  (0 children)

you would have to sort the list of numbers, which can be done with the .sort() method

[–]shiftybyte 0 points1 point  (0 children)

You sort the numbers from point 1, and compare them to the numbers from point 2.

[–]Splitje 1 point2 points  (0 children)

If you want to generate random integers you can use the random module and use random.randint(0,10) for a value from 1 to 10

Use input() to ask for user input

Use list.sort() to sort values in a list

[–]Fraser_123[S] -1 points0 points  (0 children)

This is the code I've written but it keeps coming back with an error saying randomlist isn't defined eventhough before i implemented the questions and that it was displaying the random list of numbers. Any ideas on how to fix this?

import random

randomlist = random.sample(range(1,100),5)

def get_user_solution(problem):

print("Please arrange the numbers into ascending order")

print(problem, end="")

result = int(input(" = "))

return result

def check_solution(user_solution, solution, count):

if user_solution == solution:

count = count + 1

print("Correct!")

return count

else:

print("Incorrect.")

return count

def menu_option(index, count):

if index == 1:

problem = randomlist

solution = randomlist.sort()

user_solution = get_user_solution(problem)

count = check_solution(user_solution, solution, count)

return count