我似乎无法让我的.append循环这是我到目前为止所拥有的。我也是while功能

问题描述 投票:-4回答:4

我似乎无法让我的.append循环这是我到目前为止所拥有的。我也是while功能。

a = input('options '
          '1.add a player'
          '2.remove a player'
          '3.exit')
player = []
if a == 1: player.append('players name')
python loops
4个回答
0
投票

Input返回一个字符串,而不是一个int,所以a将保存类似“1”的内容。所以在你的if语句中,比较必须是==“1”。


0
投票

在输入函数之后添加“a = int(a)”是解决问题的另一种方法,因此您可以更改“a”的数据类型。


0
投票

好的,所以这就是我到目前为止所拥有的。我得到了一切工作,除了我需要它循环所有选项,直到退出。

a = input('options '
          '1.add a player'
          '2.remove a player'
          '3. Print roster.'
          '4. name correction'
          '5.exit')
player = []
while a == '1':
 player.append(input("players name"))
 a = input('options '
          '1.add a player'
          '2.remove a player'
          '3. Print roster.'
          '4. name correction'
          '5.exit')

  if a == '2':
    player.remove(input("players name"))
    a = input('options '
          '1.add a player'
          '2.remove a player'
          '3. Print roster.'
          '4. name correction'
          '5.exit')

  if a == '3':
   print(player)
   a = input("options enter"
             "1.add a player"
             "2.remove a player"
             "3. Print roster."
             "4. name correction"
             "5.exit")
  if a == '4':
   player.remove(input("players name to correct"))
   player.append(input('correction'))
   a = input('options enter'
          '1.add a player'
          '2.remove a player'
          '3. Print roster.'
          '4. name correction'
          '5.exit')

-1
投票

我现在开始了。

a = input('options '
      '1.add a player'
      '2.remove a player'
      '3.exit')
player = []
while a == '1':
  player.append(input("players name"))
  a = input('options '
          '1.add a player'
          '2.remove a player'
          '3.exit')



print(player)
© www.soinside.com 2019 - 2024. All rights reserved.