python报错
# coding=utf-8#!/usr/bin/python
# Write Python 3 code in this online editor and run it.
from random import randint
from sys import exit
yes = 1#设全局变量
ye = 1#设全局变量
g = 1
xiao=['a','b','c','d','e','f',
'g','h','i','j','k','l',
'm','n','o','q','p','r',
't','s','u','v','w','x','y',
'z']
da =
def three_engling():
global yes#将其声明为全局变量!
global ye #将其声明为全局变量!
yes = input("是1退0")
ye = yes.isdigit() #判断字符串是否是数字,是ture 否flase
print(ye) #打印判断结果
def dcdy():
global yes
ffff = len(yes)
if ffff > 2:
print('请勿非法输入。')
cc()
def tt():
global yes #将其声明为全局变量!
global ye #将其声明为全局变量!
while ye == False:
print('请勿非法输入。')
yes = input("是1退0")
ye = yes.isdigit()
if ye == False:
print('请勿非法输入。')
cc()
else:
break
def dd():
global yes #将其声明为全局变量!
yes = int(yes)
if yes > 1:
print('请勿非法输入。')
cc()
if yes ==0:
exit(0)
def sc():
global g
y=randint(0,2) #选前三个字母的其中一个字母为小写
if y==0: #如果为零第一个字母为小写
d=randint(0,25)
one=xiao
else:
d = randint(0,25)
one = da
if y==1:#如果为1第一个字母为小写
q= randint(0,25)
two = xiao
else:
q = randint(0,25)
two = da
if y==2: #如果为2第一个字母为小写
z=randint(0,25)
three=xiao
else:
z=randint(0,25)
three=da
numbers = randint(1000000,99999999)
g=str(one)+str(two)+str(three)+'.'+str(numbers)
print(g)
def gfg():
global g
try:
f =open('three_engling.txt')
f.close('three_engling.txt')
except IOError:
f =open('three_engling.txt','w+')
f.write('\n')
f.write(g)
f.close('three_engling.txt')
cc()
else:
f =open('three_engling.txt','w')
f.write()
f.write(g)
f.close('three_engling.txt')
cc()
def cc():
three_engling()
dcdy()
tt()
dd()
sc()
gfg()
cc()
运行后122行代码报错
TextIOWrapper.close() takes no arguments (1 given)
File "/root/RemoteWorking/dd.py", line 122, in gfg
f.close('three_engling.txt')
File "/root/RemoteWorking/dd.py", line 149, in cc
gfg()
File "/root/RemoteWorking/dd.py", line 151, in <module>
cc() 本帖最后由 isdkz 于 2022-3-16 11:16 编辑
close()不需要参数
# coding=utf-8
#!/usr/bin/python
# Write Python 3 code in this online editor and run it.
from random import randint
from sys import exit
yes = 1#设全局变量
ye = 1#设全局变量
g = 1
xiao=['a','b','c','d','e','f',
'g','h','i','j','k','l',
'm','n','o','q','p','r',
't','s','u','v','w','x','y',
'z']
da =
def three_engling():
global yes#将其声明为全局变量!
global ye #将其声明为全局变量!
yes = input("是1退0")
ye = yes.isdigit() #判断字符串是否是数字,是ture 否flase
print(ye) #打印判断结果
def dcdy():
global yes
ffff = len(yes)
if ffff > 2:
print('请勿非法输入。')
cc()
def tt():
global yes #将其声明为全局变量!
global ye #将其声明为全局变量!
while ye == False:
print('请勿非法输入。')
yes = input("是1退0")
ye = yes.isdigit()
if ye == False:
print('请勿非法输入。')
cc()
else:
break
def dd():
global yes #将其声明为全局变量!
yes = int(yes)
if yes > 1:
print('请勿非法输入。')
cc()
if yes ==0:
exit(0)
def sc():
global g
y=randint(0,2) #选前三个字母的其中一个字母为小写
if y==0: #如果为零第一个字母为小写
d=randint(0,25)
one=xiao
else:
d = randint(0,25)
one = da
if y==1:#如果为1第一个字母为小写
q= randint(0,25)
two = xiao
else:
q = randint(0,25)
two = da
if y==2: #如果为2第一个字母为小写
z=randint(0,25)
three=xiao
else:
z=randint(0,25)
three=da
numbers = randint(1000000,99999999)
g=str(one)+str(two)+str(three)+'.'+str(numbers)
print(g)
def gfg():
global g
try:
f =open('three_engling.txt')
f.close()
except IOError:
f =open('three_engling.txt','w+')
f.write('\n')
f.write(g)
f.close() # close()不需要参数
cc()
else:
f =open('three_engling.txt','w')
f.write('\n') # write 需要带参数
f.write(g)
f.close()
cc()
def cc():
three_engling()
dcdy()
tt()
dd()
sc()
gfg()
cc()
页:
[1]