0

The point of this code is to input a name, and when you input the wrong name, it will ask for it again. The counter will check how many times you got the answer wrong, and once you get the right answer, it will work. The issue is that I cant get the answer to print.

counter=0

name=str(input("Input Name:"))


while name !="Ms.Lal" or "Ken'en":
    name=str(input("Input Name Again:"))
    counter+=1
if name=="Ms.Lal" or name=="Ken'en":
    print("You got the answer wrong ",counter,"times.")
p1p1p1
  • 11
  • 3

3 Answers3

0

The condition for the while loop is incorrect, should be not equal and not equal

while name != "Ms.Lal" and name != "Ken'en":
Ira
  • 11
  • 3
0

Certainly simpler:

counter=0

name=str(input("Input Name:"))

while True:
    name=str(input("Input Name Again:"))
    counter+=1
    if name=="Ms.Lal" or name=="Ken'en":
        print("You got the answer wrong ",counter,"times.")
        break

You loop until name variable gets the value you expect, you print your statement, you break the loop to exit.

Synthase
  • 5,849
  • 2
  • 12
  • 34
0
counter = 0

name = input("Input Name:")
while name not in ("Ms.Lal", "Ken'en"):
    name = input("Input Name Again:")
    counter += 1

print("You got the answer wrong ", counter, "times.")
Lior Cohen
  • 5,570
  • 2
  • 14
  • 30