简体   繁体   English

Python - 将输入作为 i 作为 for 循环的一部分

[英]Python - taking input as i as part of a for loop

I have a simple program but the input question part is not working as it should.我有一个简单的程序,但输入问题部分无法正常工作。 I simply want the "i" in the for loop, as part of the input question to the user, to print 0,1,2,3 etc.我只是希望 for 循环中的“i”作为用户输入问题的一部分,打印 0、1、2、3 等。

instead of gives an error.而不是给出错误。

Code below下面的代码

def multapp():
  
  score=0
  lives=3
  
  for i in range(4):
    answer1=input("2 x",i)
    if answer1=="2":
      print("well done child")
      score=score+1
    else:
      print("No")
      lives=lives-1
   
  print("lives:",lives)
  print("score:",score)

multapp()

Remove "2 x" from the input function:从输入 function 中删除"2 x"

def multapp():  
    score=0
    lives=3

    for i in range(4):
       answer1=input(i)
       if answer1=="2":
       print("well done child")
       score=score+1
       else:
           print("No")
           lives=lives-1

print("lives:",lives)
print("score:",score)

multapp()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM