一. 函数
1. 函数的基本使用 (重点)
"""
函数的作用:可以将具有独立功能的代码块包装成一个整体
使用函数: 1.定义函数(将具有独立功能的代码包装起来)
2.调用函数(执行包装的代码)
函数的优点:1.更方便的使用功能
2.减少重复代码,避免代码的冗余
3.有利于代码重构
"""
import random
def func1():
player = int(input("请输⼊要出的拳:⽯头(1)/剪⼑(2)/布(3)"))
computer = random.randint(1, 3)
print("玩家出拳:%s 电脑出拳:%s" % (player, computer) )
if (player == 1 and computer == 2) or \
(player == 2 and computer == 3) or \
(player ==3 and computer == 1):
print("玩家胜利")
elif computer == player:
print("平局")
else:
print("电脑胜利")
func1()
print("其他的一些功能")
func1()
2. 函数的调试
print("开始")
def func1():
print("*" * 10)
print("func1")
print("*" * 10)
func1()
print("其他一些处理")
func1()
3. 函数文档
def func1():
"""函数1
设置函数文档:在函数定义的下方第一行,添加多行注释"""
print("func1")
func1()
4. 函数参数 (重点)
def func_sum(num1, num2):
num = num1 + num2
print(num)
func_sum(1,