私は自分のコードをpythontutorとPyCharmで実行でき、それは機能します。しかし、クラスのJupyter Notebookでコードを実行しようとすると、SyntaxErrorが発生し続けます。
私はウェブを調査しました、そして私が見つけることができた唯一のことはCodeMirror問題と関係がありました。それが何であるかわからない。f-stringで何が間違っているのですか?
def list_o_matic(blank):
if new_animal == "": #check to see if nothing was entered if so then pop last animal in list
pop = animal.pop()
msg_pop = f'{pop} popped from list' # popped for list
return msg_pop
else:
if new_animal in animal: #check to see if already have animal if yes remove animal from list
remove = animal.remove(new_animal)
msg_remove = f'1 instance of {new_animal} removed from list'
return msg_remove
else:
animal.append(new_animal) #check to see if animal is not in list if so append list to add animal
msg_append = f'1 instance of {new_animal} appended to list'
return msg_append
animal = ['cat','goat','cat']
while True:
if len(animal) == 0: #check if list is empty
print("\nGoodbye!")
break
else: # get animal input
print("look at all the animals ",animal)
new_animal = input("enter the name of an animal or quit: ").lower()
if new_animal == "quit": # quit entered print msg and leave
print("\nGoodbye!")
break
else:
print(list_o_matic(new_animal),"\n")
ファイル ""、6行目msg_pop = f '{pop}がリストからポップされました'#リストにポップされました^ SyntaxError:無効な構文
変更してみてください
msg_pop = f{'pop'}
に
msg_pop = f'{pop}'
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加