0
Error in a Y/N question
words = ["hello", "world", "spam", "eggs"] p = input("Items? ") words.append(p) counter = 0 n = 1 input1 = True while input1 == True: while counter < len(words): word = words[counter] print("[" + str(n) + "]" + word) counter += 1 n += 1 input = input("Wanna do it again[Y/N] ") if input = "y": input1 = True elif input = "n": input1 = False else: print("You didn't choose Y or N...") input1 = False
2 Answers
+ 1
1)don't use input as variable name
2)= is not a relational operator...use == in boolean expression
3)put line 2,3,4,5 within while loop
#try to analyze the below code
words = ["hello", "world", "spam", "eggs"]
input1=True
while input1==True:
p=input("items?")
words.append(p)
counter=0
n=1
while counter < len(words):
word=words[counter]
print("[" + str(n) + "]" + word)
counter+=1
n+=1
input_ = input("Wanna do it again[Y/N] ")
if input_ == "y":
input1=True
elif input_ == "n":
input1=False
else:
print("You didn't choose Y or N...")
input1 = False
+ 1
Thank you very much