python的字符串 --综合练习题
程序员文章站
2024-03-08 09:32:52
...
练习一
设计一个程序,帮助小学生练习10以内的加法
详情:
- 随机生成加法题目;
- 学生查看题目并输入答案;
- 判别学生答题是否正确?
- 退出时, 统计学生答题总数,正确数量及正确率(保留两位小数点);
- import random # 导入随机数的函数库
all_number = 0 # 答题总数定义为0
right_number = 0 # 正确总数定义为0
for i in range(1, 100): ##循环1~100个加法题
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))
结果
练习二
小学生算术能力测试系统:
设计一个程序,用来实现帮助小学生进行百以内的算术练习,
它具有以下功能:提供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('算术练习不过关,别灰心,加油!!!')
结果
上一篇: C语言基础之运算符和表达式-笔记四
下一篇: Pycharm 报错 “Could not find conda environment: torch“ 解决办法:通过Anaconda 配置 pytorch 环境
推荐阅读
-
SparkStreaming综合整体的练习题![强烈推荐]
-
python的字符串 --综合练习题
-
python------字典的综合练习题
-
函数的练习题答案--python
-
python的函数--练习题
-
Python对字符串实现去重操作的方法示例
-
Python 由字符串函数名得到对应的函数(实例讲解)
-
关于Python中空格字符串处理的技巧总结
-
python进阶练习题:排序CSV文件的列【难度:2级】--景越Python编程实例训练营,不同难度Python习题,适合自学Python的新手进阶
-
python基础练习题:删除第一次和最后一个字符【难度:0级】--景越Python编程实例训练营,不同难度Python习题,适合自学Python的新手进阶