Pycharm“完成,退出代码为0”

问题描述 投票:-1回答:1
def main():
countries = ("England", "Palestine", "Israel", "Uzbekistan", "DRC" )
print(countries)
choice = input("Please pick one of these countries: ")
if choice == "England":
    print(countries[0])
elif choice == "Palestine":
    print(countries[1])
elif choice == "Israel":
    print(countries[2])
elif choice == "Ubekistan":
    print(countries[3])
elif choice == "DRC":
    print(countries[4])
else:
    print("Please enter a country on the list!")
    main()
main()

[每当我在pycharm上运行此代码时,我都会收到“进程已完成,退出代码为0”。我使用“ Shift + F10”运行。

python arrays python-3.x pycharm
1个回答
0
投票

不确定在pycharm]中运行这段代码时,您的电脑到底出了什么问题,但我在线使用了以下内容,我注意到的一个主要问题是,经过适当的缩进后,您的缩进问题在代码中可以正常运行了关注在线python解释器,link

def main():
  countries = ("England", "Palestine", "Israel","Uzbekistan", "DRC")
  print(countries)
  choice = input("Please pick one of these countries: ")
  if choice == "England":
      print(countries[0])
  elif choice == "Palestine":
      print(countries[1])
  elif choice == "Israel":
      print(countries[2])
  elif choice == "Ubekistan":
      print(countries[3])
  elif choice == "DRC":
      print(countries[4])
  else:
      print("Please enter a country on the list!")
      main()
main()

为了以后的工作,最好在脚本的开头(写了main()的位置)添加以下内容:

if __name__=='__main':
    main()
© www.soinside.com 2019 - 2024. All rights reserved.