因此,当我尝试将参数 num1 和 num2 传递给函数 gcd 时,我遇到了字符串格式错误。我不知道如何解决这个问题。请多多包涵,因为我是 Python 编程新手。谢谢!
#!/usr/bin/python
import sys
from collections import defaultdict
lines = sys.stdin.read()
lineArray = lines.split()
listLength = len(lineArray)
def gcd(a, b):
c = 0
if a > b:
r = a%b
if r == 0:
return b
else:
return gcd(b, r)
if a < b:
c = b
b = a
a = c
return gcd(a, b)
for x in range(0, listLength):
num1 = lineArray[x]
num2 = lineArray[x+1]
print num1, 'and', num2
print gcd(num1, num2)
print 'end'