欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python的字符串 --综合练习题

程序员文章站 2024-03-08 09:32:52
...

练习一

设计一个程序,帮助小学生练习10以内的加法
详情:

  • 随机生成加法题目;
  • 学生查看题目并输入答案;
  • 判别学生答题是否正确?
  • 退出时, 统计学生答题总数,正确数量及正确率(保留两位小数点);
- import random  # 导入随机数的函数库

all_number = 0  # 答题总数定义为0
right_number = 0  # 正确总数定义为0
for i in range(1, 100):  ##循环1100个加法题
    student_choose = int(input('做题模式1、退出模式2'))
    if student_choose == 1:
        num1 = random.randint(1, 10)
        num2 = random.randint(1, 10)
        answer = num1 + num2  ##内部求和
        print('%d+%d=___' % (num1, num2))
        student_answer = int(input('请输入正确答案:'))
        if student_answer == answer:
            right_number += 1
            all_number += 1
            i += 1
        else:
            all_number += 1
            i += 1
    else:
        print('bye!!!')
        break
precision=right_number/all_number*100
print('你总共答了%d题,做对了%d题,正确率为%.2f%%' %(all_number,right_number,precision)

python的字符串 --综合练习题

结果
python的字符串 --综合练习题

练习二

小学生算术能力测试系统:
设计一个程序,用来实现帮助小学生进行百以内的算术练习,
它具有以下功能:提供9道加、减、乘或除四种基本算术运算的题目;
练习者根据显示的题目输入自己的答案,
程序自动判断输入的答案是否正确并显示出相应的信息。

import random

all_number = 0
right_number = 0
for i in range(1, 10):
    student_choose = int(input('请选择模式-1答题,2退出:'))
    if student_choose == 1:
        num1 = random.randint(1, 100)
        num2 = random.randint(1, 100)
        # if num1 < num2:
        #     a = num1
        #     num1 = num2
        #     num2 = a
        offer_choose = ['+', '-', '*', '/']
        already_choose = random.choice(offer_choose)
        if already_choose == '+':
            answer = num1 + num2
            print('%d+%d=__' % (num1, num2))
            student_answer = int(input('请给出你的答案:'))
            if student_answer == answer:
                all_number += 1
                right_number += 1
                i += 1
            else:
                all_number += 1
                i += 1
        if already_choose == '-':
            answer = num1 - num2
            print('%d-%d=__' % (num1, num2))
            student_answer = int(input('请给出你的答案:'))
            if student_answer == answer:
                all_number += 1
                right_number += 1
                i += 1
            else:
                all_number += 1
                i += 1
        if already_choose == '*':
            answer = num1 * num2
            print('%d*%d=__' % (num1, num2))
            student_answer = int(input('请给出你的答案:'))
            if student_answer == answer:
                all_number += 1
                right_number += 1
                i += 1
            else:
                all_number += 1
                i += 1
        if already_choose == '/':
            answer = num1 / num2
            print('%d/%d=__' % (num1, num2))
            student_answer = float(input('请给出你的答案:'))
            if student_answer == answer:
                all_number += 1
                right_number += 1
                i += 1
            else:
                all_number += 1
                i += 1
    else:
        print('bye!!!')
        break
precision = right_number / all_number * 100
print('你总共答了%d题,答对了%d道,正确率为%.2f%%' % (all_number, right_number, precision))
if precision > 60.00:
    print('恭喜你,算术练习过关,再接再砺!!!')
else:
    print('算术练习不过关,别灰心,加油!!!')

结果
python的字符串 --综合练习题

相关标签: python