1、编写一个程序,要求该程序运行后,生成一个名为“new.py”的文件,在每一行后面添加行号,且行号以"#"开头,即行号为注释信息,不影响程序的正常执行。同时要求所有行的"#"号垂直对齐。
2条回答 默认 最新
- HMMHMH 2019-12-25 17:43关注
import random import string class Game: def __init__(self): self.total_count = 0 self.right_count = 0 self.len = 15 def play(self): n = int(input('请输入打字次数:')) while n: right = 0 print('游戏次数剩余{}次'.format(n)) word = ''.join(random.sample(string.ascii_letters + string.digits + ' ', random.randint(1, self.len))) print(word) res = input() if len(res) != len(word): print('输入的字符串超长,无效') self.total_count += len(word) n -= 1 continue for i in zip(word, res): if i[0] == i[1]: right += 1 self.right_count += right self.total_count += len(word) print('本次的正确率为{:.2f}%\n'.format(right * 100 / len(word))) n -= 1 print('整体的正确率为{:.2f}%'.format(self.right_count * 100 / self.total_count)) if __name__ == '__main__': Game().play()
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 3无用
悬赏问题
- ¥15 易盾点选的cb参数怎么解啊
- ¥15 MATLAB运行显示错误,如何解决?
- ¥15 c++头文件不能识别CDialog
- ¥15 Excel发现不可读取的内容
- ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
- ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
- ¥20 yolov5自定义Prune报错,如何解决?
- ¥15 电磁场的matlab仿真
- ¥15 mars2d在vue3中的引入问题
- ¥50 h5唤醒支付宝并跳转至向小荷包转账界面