python 加减小游戏,python减小游戏,from operato
文章由Byrx.net分享于2019-03-23 09:03:18
python 加减小游戏,python减小游戏,from operato
from operator import add,subfrom random import randint,choiceops={'+':add,'-':sub}MAXTRIES=2def doprob(): op=choice("+-") nums=[randint(1,10) for i in range(2)] nums.sort(reverse=True) ans=ops[op](*nums) pr='%d %s %d='%(nums[0],op,nums[1]) oops=0 while True: try: if int(input(pr))==ans: print('correct') break if oops==MAXTRIES: print('answer:',pr,ans) else: print("incorrect ...try again") oops+=1 except ValueError as e: print('input err',e)def main(): while True: doprob() try: opt=input('again ? [y]').lower() if opt and opt[0]=='n': break except EOFErroe as e: breakif __name__=='__main__': main()#该片段来自于http://byrx.net
相关内容
- python 枚举系统进程,python枚举进程,from ctypes.
- 支持ftp上传下载文件和目录,ftp上传下载文件,支持ft
- 改进emacs里看糗百,改进emacs糗百,写代码写累了,可以
- 批量生成ETL Automation APP下Perl脚本执行目录,etlperl,imp
- Python异步任务队列,python异步队列,#!/usr/bin/e
- 再一个生成随机mac地址的脚本,生成mac脚本,#!/usr/bin/
- 命令行看糗百,命令行糗百,#!/usr/bin/e
- 一个用python写的用命令行看糗百的小工具,python,最近正
- 简单多线程字典暴力破解web表单,暴力破解web表单,py
- Python下的一些随机化算法,Python随机化算法,# -*- codin
评论关闭