PYTHON QUESTION: I want to put else statement too. If i put the \"Print (c) and
ID: 3774331 • Letter: P
Question
PYTHON QUESTION:
I want to put else statement too. If i put the "Print (c) and b=input("enter a letter"), then it will print things multiple times which i dont want. What do i need to do so that if userInput matches any letters of the word, it replaces all in c,else count=count-1, and asks userInput in loop. When 0,game over.
a apple b input ("enter a letter court-5 while c! a for i in range (len(a) if b ali it wil replace all the position on c print (c) b input ("enter a letter nog c pp suppose user input was "p" else: I can't put else statement there. It says invalid syntaxD count-count-i sir put("enter a letter bExplanation / Answer
You did well upto for loop declaration but the problem is in for loop :
You should check whether the input character is present in string then decrement count ,so it would be like this within the while loop :
while count>=0:
flag=0
if count==0:
print 'Game over'
break
for i in range(len(a)):
if b==a[i]:
c[i]=b
flag=1
if flag==0:
count=count-1
b=input('enter a letter : ');
else:
print(c)
break
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.