最近我一直在玩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