Vâng, random.randint[]
trả về một danh sách với các số nguyên được đặt trong một số ngẫu nhiên. Những gì bạn thực sự cần là random.shuffle[]
. Vì vậy, bạn nên lập một danh sách [tôi sẽ gọi nó là questions
] vì random.shuffle
chỉ hoạt động khi có một danh sách trong ngoặc đơn. Điều này sẽ hoạt động bởi vì tất cả những gì bạn cần làm là đưa câu hỏi của bạn vào danh sách và để random.shuffle[]
thực hiện phép thuật của nó:
questions = ['Question 1', 'Question 2', 'Question 3'] #You can add as many questions as you like
random.shuffle[questions] #Mixes the items in "questions" into a random order
print questions[0]
print questions[1]
print questions[2]
Và có nhiều kết hợp/kết quả khác nhau mà bạn có thể nhận được bằng cách sử dụng random.shuffle[]
theo cách này. Để có câu trả lời, cùng một ý tưởng, ngoại trừ bạn cần một vòng lặp
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
2 và biết thứ tự của các câu hỏi để bạn có thể chọn các lựa chọn trả lời đúng cho mỗi câu hỏi. Vẫn thêm random.shuffle[]
cho câu trả lời:questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
Sử dụng
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
4, bạn có thể kiểm tra câu trả lời từ questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
5 với câu hỏi chính xác với câu hỏi tương ứng. Làm thế nào bạn làm đó là sự lựa chọn của bạn. Đây phải là một cơ sở để giúp bạn. Đặt một câu hỏi về Python.
Câu hỏi = đầu vào ["câu hỏi của bạn"].
Nếu câu hỏi == ["Có"].
In ["Làm tốt"].
Elif câu hỏi == ["Không"].
random.shuffle[mylist]
print[mylist]
in ["thử lại"].
Phương pháp ngẫu nhiên
Thí dụ
Shuffle một danh sách [tổ chức lại thứ tự của các mục danh sách]: This method changes the original list, it does not return a new list.
Nhập ngẫu nhiên
mylist = ["Apple", "chuối", "anh đào"] ngẫu nhiên.shuffle [mylist]
Hãy tự mình thử »
Lưu ý: Phương pháp này thay đổi danh sách ban đầu, nó không trả về một danh sách mới. | Cú pháp |
ngẫu nhiên.shuffle [trình tự, chức năng] | Giá trị tham số If not specified, the function 7 will be used
|
Tham số
Câu hỏi = đầu vào ["câu hỏi của bạn"].
Nếu câu hỏi == ["Có"].
In ["Làm tốt"].
In ["Làm tốt"].
Elif câu hỏi == ["Không"].
return 0.1
in ["thử lại"].
random.shuffle[mylist, myfunction]
print[mylist]
in ["thử lại"].
Đặt một câu hỏi về Python.
Xáo trộn một chuỗi các con số luôn là một tiện ích hữu ích và câu hỏi đã xuất hiện trong nhiều cuộc phỏng vấn vị trí của công ty. Biết nhiều hơn một phương pháp để đạt được điều này luôn có thể là một điểm cộng. Hãy để thảo luận về một số cách nhất định trong đó điều này có thể đạt được.Method #1: FisherTHER Yates Shuffle Thuật toán này là một trong những thuật toán nổi tiếng chủ yếu được sử dụng để xáo trộn một chuỗi số trong Python. Thuật toán này chỉ lấy giá trị chỉ số cao hơn và hoán đổi nó với giá trị hiện tại, quá trình này lặp lại trong một vòng lặp cho đến cuối danh sách. & NBSP; & nbsp;
Method #1 : Fisher–Yates shuffle Algorithm
This is one of
the famous algorithms that is mainly employed to shuffle a sequence of numbers in python. This algorithm just takes the higher index value, and swaps it with current value, this process repeats in a loop till end of the list.
Python3
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
8 questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
9The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]0____21
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]22____23
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]5
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]7
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]9
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]1
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]2
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]3
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]5
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]6
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]7
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]8
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]9
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]0
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]1
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]2
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]5
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]6
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]3
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]9
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4__
Các
Original List: [1, 2, 3, 4, 5, 6] Shuffled List: [4, 5, 3, 2, 6, 1]4
random.randint[]
4The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]1
random.randint[]
6The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]3
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]4
random.randint[]
9 ________ 36 & nbsp; The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]7
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]8
Output:
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]
& nbsp; & nbsp; Phương thức #2: sử dụng Random.shuffle [] & nbsp; Đây là phương thức được khuyến nghị nhất để xáo trộn danh sách. Python trong thư viện ngẫu nhiên của nó cung cấp chức năng sẵn có này mà tại chỗ xáo trộn danh sách. Hạn chế của điều này là đặt hàng danh sách bị mất trong quá trình này. Hữu ích cho các nhà phát triển chọn tiết kiệm thời gian và hối hả. & Nbsp;
Method #2 : Using random.shuffle[]
This is most recommended method to shuffle a list. Python
in its random library provides this inbuilt function which in-place shuffles the list. Drawback of this is that list ordering is lost in this process. Useful for developers who choose to save time and hustle.
Python3
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
8 questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
9The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]0____21
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]22____23
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]5
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]7
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]9
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]1
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]2
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]3
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]5
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]6
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]7
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]8
random.shuffle
4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]3
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]4
random.randint[]
9 ________ 36 & nbsp; The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]7
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]8
Output:
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]
& nbsp; & nbsp; Phương thức #2: sử dụng Random.shuffle [] & nbsp; Đây là phương thức được khuyến nghị nhất để xáo trộn danh sách. Python trong thư viện ngẫu nhiên của nó cung cấp chức năng sẵn có này mà tại chỗ xáo trộn danh sách. Hạn chế của điều này là đặt hàng danh sách bị mất trong quá trình này. Hữu ích cho các nhà phát triển chọn tiết kiệm thời gian và hối hả. & Nbsp;
Method #3 : Using random.sample[]
This is quite a useful function, better than the shuffle method used above in aspect that it creates a new shuffled list and returns it rather than disturbing the order of original list. This is useful in cases we require to retain the original list.
Python3
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
8 questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
9The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]0____21
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]22____23
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]5
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]7
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]9
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]1
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]2
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]3
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]5
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]6
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]7
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]8
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]9
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]0
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]1
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]2
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]5
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]6
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]3
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]9
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]4__
Các
Output:
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]
Original List: [1, 2, 3, 4, 5, 6]
Shuffled List: [4, 5, 3, 2, 6, 1]
4random.randint[]
4The original list is : [1, 4, 5, 6, 3]
The shuffled list is : [4, 3, 1, 5, 6]
1 random.randint[]
6
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]3
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]4
random.randint[]
9 ________ 36 & nbsp; The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]7
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]8
Python3
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
8 questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
9Các
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]3
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]4
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
52questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
53questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
54The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]1
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]4
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
57The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]9
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]0
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]1
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]2
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
62Original List: [1, 2, 3, 4, 5, 6] Shuffled List: [4, 5, 3, 2, 6, 1]4
Original List: [1, 2, 3, 4, 5, 6] Shuffled List: [4, 5, 3, 2, 6, 1]55____21
Original List: [1, 2, 3, 4, 5, 6] Shuffled List: [4, 5, 3, 2, 6, 1]7
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]9
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
68The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 3, 6, 1, 4]6
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]3
random.randint[]
2Original List: [1, 2, 3, 4, 5, 6] Shuffled List: [4, 5, 3, 2, 6, 1]4
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
73The original list is : [1, 4, 5, 6, 3] The shuffled list is : [4, 3, 1, 5, 6]1
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
75Original List: [1, 2, 3, 4, 5, 6] Shuffled List: [4, 5, 3, 2, 6, 1]4
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
77The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]3
The original list is : [1, 4, 5, 6, 3] The shuffled list is : [5, 6, 4, 3, 1]4
questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
80questions = ['Question 1', 'Question 2', 'Question 3']
originals = [['Question 1', 'a1'], ['Question 2', 'b1'], ['Question 3', 'c1']]
answers = [['a1'], ['a2'], ['a3']], [['b1'], ['b2'], ['b3']], [['c1'], ['c2'], ['c3']] #List of answers for each question
selected_answers = [] #Contains selected answers
random.shuffle[questions]
random.shuffle[answers[0]]
random.shuffle[answers[1]]
random.shuffle[answers[2]]
question = 0
while question < 4:
if questions[0] == 'Question 1':
print 'Question 1'
print answers[0][0], answers[0][1], answers[0][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 2':
print 'Question 2'
print answers[1][0], answers[1][1], answers[1][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
elif questions[0] == 'Question 3':
print 'Question 3'
print answers[2][0], answers[2][1], answers[2][2]
chosen = raw_input['Enter 1 for the first answer, 2 for the second answer and 3 for the third one.']
selected_answers.append[chosen]
del questions[0]
question += 1
81Đầu ra
Original List: [1, 2, 3, 4, 5, 6] Shuffled List: [4, 5, 3, 2, 6, 1]