Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Life counter not working
#2
The code gives
Error:
TypeError: 'int' object is not subscriptable
The function guess is called twice to get the return of wordMask and livesLost.
It currently only returns livesLost (the first return it gets to)
To make it work you could change the code to only call guess once and return both wordMask and livesLost

def guess(myWord,wordMask,lengthOfWord,livesLost):
    ...
    ...
    if not correct:
        livesLost = livesLost + 1
        print("Life Lost")
        print(livesLost)
    return livesLost, wordMask
    # print(wordMask)
    # return wordMask

...
...
while wordFinished == False:
    wordFinished = wordComplete(wordMask,myWord,lengthOfWord)
    # wordMask = guess(myWord,wordMask,lengthOfWord,livesLost)
    livesLost, wordMask = guess(myWord,wordMask,lengthOfWord,livesLost)
Reply


Messages In This Thread
Life counter not working - by joshp2709 - Oct-05-2019, 09:03 AM
RE: Life counter not working - by Yoriz - Oct-05-2019, 10:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I can't for the life of me get this basic If statement code to work CandleType1a 8 2,140 May-21-2024, 03:58 PM
Last Post: CandleType1a
  Optimize a game of life (4 sec for python when 6 ms for C version !) fatango 0 2,114 Jan-06-2021, 09:13 PM
Last Post: fatango
  Problem in a path finding algorithm (counter is not working) Kowalski 3 3,993 Feb-05-2018, 01:23 PM
Last Post: Gribouillis
  Keep a file locked for the life of an application rachelrosemond 2 3,924 Oct-03-2017, 04:37 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020