24_python实操案例十
2022/8/6 1:52:47
本文主要是介绍24_python实操案例十,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
任务一:
def calc(a, b, op): if op == "+": return add(a, b) elif op == "-": return sub(a, b) elif op == '*': return mul(a, b) elif op == "/": if b!= 0: return div(a, b) else: return '除数不能为0' else: print("输入的运算符不正确!!") def add(a, b): return a + b def sub(a, b): return a - b def mul(a, b): return a * b def div(a, b): return a / b if __name__ == '__main__': a = int(input('请输入第一个整数:')) b = int(input('请输入第二个整数:')) op = input('请输入运算符:') print(calc(a, b, op))
任务二:
import random def guess(num,guess_num): if num == guess_num: return 0 elif guess_num>num: return 1 else: return -1 num = random.randint(1, 100) for i in range(10): guess_num = int(input('我心里有个【1-100】的整数请你猜一下:')) result = guess(num, guess_num) if result == 0: print('猜对了') break elif result ==1: print('大了') else: print('小了') else: print('真笨,10次都没有猜中!')
这篇关于24_python实操案例十的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门
- 2024-11-14Python编程入门指南
- 2024-11-13Python基础教程
- 2024-11-12Python编程基础指南
- 2024-11-12Python基础编程教程
- 2024-11-08Python编程基础与实践示例
- 2024-11-07Python编程基础指南