小编Ogo*_*ugh的帖子

整数之和-'int'对象不可迭代

我的问题与python中的sum函数有关。

所以我的代码是

def black_jack(a, b):
    if sum(a, b) > 21:
        return 0
    else:
        return sum(a, b)


print black_jack(10, 5)
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:

'int' object is not iterable
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么会发生这种情况以及如何解决吗?

python

1
推荐指数
1
解决办法
4628
查看次数

在阅读之前必须关闭文件吗?蟒蛇

该程序只需一个文件,删除它,允许用户输入两行放入空白文件,然后打印文件.

但为什么我必须关闭文件对象并在显示新添加的行之前重新打开它?

(请注意,此版本的代码中不会打印该文件.但如果删除了#,它将正确执行)

from sys import argv

sript, filename = argv

print "We will be buliding a new file from an %s" % filename
print "If you don't want to do this, hit CTRL_C"
print "If you do, hit and other key"

raw_input(">>>")

print "Oppening the file..."
file_ob = open(filename, "r+")
file_ob.truncate()

print "Now we will rewrite this file with the following line"
line1 = raw_input("The fist line will be :")
line2 = raw_input("The second line will be:")

print "Now …
Run Code Online (Sandbox Code Playgroud)

python

1
推荐指数
1
解决办法
44
查看次数

标签 统计

python ×2