data = StringIO(u"""What is the fastest type of storage?
Which register stores the results of calculations carried out by the ALU?
Which bus sends data to the CPU from the RAM?
What is 10110110 in denary?
What is 7D in denary?
In which topology is each computer connected individually to a central point?
What is half a byte known as?
What is 142 in binary?
What is each column known as in a record?
What is a variable which is available anywhere in a program known as?""")
import random
import csv
csv_reader = csv.reader(data)
questions = list(csv_reader)
random_question = random.choice(questions)
print(random_question)
您可以使用^{} 在csv中获得一个随机行,如下所示:
代码:
注意,这将返回一个与csv行相对应的列表。若要获取特定列,然后可以选择如下所示:
^{pr2}$测试代码:
结果:
相关问题 更多 >
编程相关推荐