如何添加功能,并把它表尺返回结果?python



我想创建一个函数来返回一个结果,如果我把里面是2米到达那里?

下面的代码:

num1 = int(input('put the number 1 : '))
num2 = int(input('put the number 2 : '))
def permitation(n1,n2):
nn1 = n1
n1 = n2
n2 = nn1
return num1,num2

permitation(num1,num2)

print('num1 : {}'.format(num1))
print('num2 : {}'.format(num2))
输出:

put the number 1 : 10
put the number 2 : 1
num1 : 10
num2 : 1

但是我需要:

put the number 1 : 10
put the number 2 : 1
num1 : 1
num2 : 10

帮帮我吧

看到问题和答案时,我想我中风了

num1, num2 = num2, num1

您不需要所有这些额外的变量:

def swap(n1, n2):
return n2, n1
num1, num2 = swap(num1, num2)

当然,你根本不需要一个函数。

num1, num2 = num2, num1

最新更新