Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSV quiz
#1
I need to create a system where priority is given to choosing questions out of a list with the lowest number of times answered correctly first.

Any ideas what I could do?
Reply
#2
Make a list of lists, with the sub-lists being the number of correct answers and the question.

questions = [[3, 'What is your name?'], [3, 'What is your quest?'], [1, 'What is your favorite color?'], [0, 'What is the capital of Assyria?']]
That will allow you to keep track of the number of correct answers, and you can sort the list to get the lowest number of correct answers first.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Thankyou so much.
Any idea on how to sort the list?
Reply
#4
You might want to check out this tutorial on lists.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
The list object has sort() method or you can use sorted() built-in function if you don't want to be done in place.

>>> questions = [[3, 'What is your name?'], [3, 'What is your quest?'], [1, 'Wha
... t is your favorite color?'], [0, 'What is the capital of Assyria?']]

>>> sorted_q = sorted(questions, key=lambda x: x[0])

>>> sorted_q
[[0, 'What is the capital of Assyria?'], [1, 'What is your favorite color?'], [3, 'What is your name?'], [3, 'What is your quest?']]
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020