1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| import random
info = {'北京': '京', '天津': '津', '河北': '冀', '山西': '晋', '内蒙古': '蒙', '辽宁': '辽', '吉林': '吉', '黑龙江': '黑', '上海': '沪', '江苏': '苏', '浙江': '浙', '安徽': '皖', '福建': '闽', '江西': '赣', '山东': '鲁', '河南': '豫', '湖北': '鄂', '湖南': '湘', '广东': '粤', '广西': '桂', '海南': '琼', '重庆': '渝', '四川': '川、蜀', '贵州': '贵、黔', '云南': '云、滇', '西藏': '藏', '陕西': '陕、秦', '甘肃': '甘、陇', '青海': '青', '宁夏': '宁', '新疆': '新', '台湾': '台', '香港特别行政区': '港', '澳门特别行政区': '澳', } letters = ['A', 'B', 'C', 'D']
for quiz_num in range(30): quiz_file = open(f'试题/试题{quiz_num + 1}.txt', 'w', encoding='utf-8') answer_file = open(f'答案/答案{quiz_num + 1}.txt', 'w', encoding='utf-8') quiz_file.write('姓名:\t\t日期:\t\t年级:\t\t\n\n') quiz_file.write((' ' * 20) + f'省份简称试题 (卷{quiz_num + 1})') quiz_file.write('\n\n') provinces = list(info.keys()) random.shuffle(provinces) for question_num in range(34): province = provinces[question_num] correct_answer = info[province] wrong_answers = list(info.values()) del wrong_answers[wrong_answers.index(correct_answer)] wrong_answers = random.sample(wrong_answers, 3) answer_options = wrong_answers + [correct_answer] random.shuffle(answer_options) quiz_file.write(f'{question_num + 1}. {provinces[question_num]}的简称是?\n') for i in range(4): quiz_file.write(f'{letters[i]}. {answer_options[i]} \t') quiz_file.write('\n') answer_file.write(f'{question_num + 1}. {letters[answer_options.index(correct_answer)]}\t') quiz_file.close() answer_file.close()
|