最近我一直在玩Python,并且在创建函数时碰到过这个错误。我似乎无法修复它:(CODE:Python说:“预计一个缩进块”
的Python
#Python
choice = input('Append Or Write?')
if choice == "write":
def write():
pass
text_file = open('WrittenTXT.txt', "w")
type_user = input('Type: ')
text_file.write(type_user)
text_file.close()
if choice == "append":
def append():
# Making a txt file
#Append
pass
text_file = open('WrittenTXT.txt', "a")
user_int = input('Enter An Integer: ')
space = "\n" * 2
lines = [space, "Hi\n", "Hallo\n", "Bonjour\n", user_int]
text_file.writelines(lines)
text_file.close()
是这部分功能吗?很难说。记得在python中,缩进定义范围。你的第一行(从'choice'开始)不与'直接在它下面的行对齐。可能是你在StackOverlow中的格式,但我怀疑它。返回代码并确保同一范围内的行对齐。 –
错误的格式化代码是您的问题。我提到你在提出模糊问题之前阅读关于Python的基础知识。 – dannyxn