小朋友口算练习题,100以内的加减法运算:
程式要求如下
1,100道100以内的加减法计算题
2,两数相加,和小于等于100
3,被减数必须大于减数
4,前面80道计算题的格式为A+B= 或者C-D= 两种格式
5,最后20道计算题的格式为A-(B-C)= 或者 A+(B+C) 或者A+(B-C)= 或者A-(B+C)= 四种格式
6,一列5道题,一页20列,每一列计算题必须绝对左对齐
7,每一道题目的前面不需要顺序编号
python代码实现
大家帮助一年级小朋友练习口算题,可以借鉴:
import random/* 导入 random 模块,用于生成随机数 */def generate_simple_questions(num_questions):questions = []/* 创建一个空列表,用于存储生成的问题 */for _ in range(num_questions):a = random.randint(1, 100)b = random.randint(1, 100)/* 生成两个随机整数 a 和 b */if a + b <= 100:question = f"{a}+{b}="else:if a > b:question = f"{a}-{b}="else:question = f"{b}-{a}="/* 根据 a 和 b 的和是否小于等于 100,生成加法或减法问题 */questions.append(question)return questions/* 将生成的问题添加到 questions 列表中并返回 */def generate_complex_questions(num_questions):questions = []/* 创建一个空列表,用于存储生成的问题 */for _ in range(num_questions):a = random.randint(1, 100)b = random.randint(1, 100)c = random.randint(1, 100)/* 生成三个随机整数 a、b 和 c */question_type = random.randint(1, 4)/* 生成一个随机整数,用于决定问题类型 */if question_type == 1:question = f"{a}-({b}-{c})="elif question_type == 2:question = f"{a}+({b}+{c})="elif question_type == 3:question = f"{a}+({b}-{c})="else:question = f"{a}-({b}+{c})="/* 根据问题类型生成复杂问题 */questions.append(question)return questions/* 将生成的问题添加到 questions 列表中并返回 */def print_questions(questions, num_columns, num_rows):for row in range(num_rows):for column in range(num_columns):question = questions[row * num_columns + column]print(f"{question:<15}", end="")print()/* 按照指定的行和列打印问题 */simple_questions = generate_simple_questions(80)complex_questions = generate_complex_questions(20)all_questions = simple_questions + complex_questions/* 生成简单和复杂问题,并将它们合并到一个列表中 */print_questions(all_questions, 5, 20)/* 按照 5 列 20 行的格式打印问题 */
执行结果参考如下图:
希望以上可以帮助到大家。谢谢!