Python Forum
Need Help debugging program - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Need Help debugging program (/thread-1215.html)

Pages: 1 2


Need Help debugging program - ToastyCoder - Dec-13-2016

I have had problems with a class project for about a week now, with displaying list items from a multiline string, and i also need help with general debugging, pm and i can send the code so you can help me out, thx  Smile Cool Cool



RE: Need Help debugging program - micseydel - Dec-13-2016

We're not going to help over PMs, you'll have to post code with your question about it. I realize there can be issues with sharing code for a class, but typically the most effective posts don't include your whole script, just the minimal amount of code to reproduce your problem that you're confused about. If you post right, it shouldn't be a problem :)


RE: Need Help debugging program - Kebap - Dec-13-2016

(Dec-13-2016, 06:52 PM)ToastyCoder Wrote:
displaying list items from a multiline string

my_string = """
line one
line two
line three
"""
my_list = my_string.split("\n")
print(my_list[2:3])
(Dec-13-2016, 06:52 PM)ToastyCoder Wrote:
general debugging

print is your friend there. When in doubt, just print the value of your variables and compare with what you'd expect them to be.


RE: Need Help debugging program - ToastyCoder - Dec-15-2016

(Dec-13-2016, 06:56 PM)micseydel Wrote: We're not going to help over PMs, you'll have to post code with your question about it. I realize there can be issues with sharing code for a class, but typically the most effective posts don't include your whole script, just the minimal amount of code to reproduce your problem that you're confused about. If you post right, it shouldn't be a problem  :)


import random
BunkerPics = ['''
+----------+
| [_]  [_] |
|          |
|   [__]   |
|          |
|[_]    [_]|
============''','''

+----------+
| [_]  [_] |
|          |
|   [00]   |
|          |
|[_]    [_]|
============''','''

+----------+
| [0]  [_] |
|          |
|   [00]   |
|          |
|[_]    [_]|
============''','''

+----------+
| [0]  [0] |
|          |
|   [00]   |
|          |
|[_]    [_]|
============''','''

+----------+
| [0]  [0] |
|          |
|   [00]   |
|          |
|[0]    [_]|
============''','''
+----------+
| [0]  [0] |
|          |
|   [00]   |
|          |
|[0]    [0]|
============''','''
      ,-'""`-,               
    ,'        `.             
   /    _,,,_   \            
  /   ,'  |  `\/\\           
 /   /,--' `--.  `           
 |   /      ___\_            
 |  | /  ______|             
 |  | |  |_O \O|             
 \ ,' (   _) -`|             
  '--- \ '-.(0) /             
 ______/`--'--<              
 |    |`-.  ,;/``--._        
 |    |-. _///     ,'`\      
 |    |`-Y;'/     /  ,-'\    
 |    | // <_    / ,'  ,-'\  
 '----'// -- `-./,' ,-'  \/  
  |   //[--]     \,' \_.,-\  
  |  //      `  -- | \__.,-' 
    // -[--]_      |   ____\ 
   //          `-- |--' |   \
        [--]_,,,,--'    |-'" 
    ---""''             |    
             ___...____/     ''']

Kills = '135 119 124 287 465 097 467 184 263 276 356 472 876 917 845 645 237 287 193 468 283 376 197'.split()

def getRandomNo(Kills):
    KillIndex = random.randint(0, len(Kills) - 1)
    return Kills[KillIndex]

def displayBoard(BunkerPics, ShotsMissed, ShotsLeft, GoodShots,):
    print(BunkerPics[len(ShotsLeft)])
    print()

    print('SHOTS MISSED:', ShotsLeft , end='')
    for number in ShotsMissed:
        print(number, end(''))
        print()

    blanks = '' * len(ShotsMissed)

    for i in range(len(ShotsHit)):
        if ShotsHit[i] in GoodShots:
            blanks = blanks[:i] + ShotsHit[i] + blanks[i+1:]

    for number in blanks:
        print(number, end='')
    print()

def getGuess(alreadyGuessed):
    while True:
        print('Pick a number to take a shot')
        guess = input()
        guess = guess.lower()
        if len(guess) != 1:
            print('Please enter only one number')
        elif guess in alreadyGuessed:
            print('You already guessed that number. Pick another number')
        elif guess not in '1234567890':
            print('Please Enter a NUMBER. God why do people not listen')
        else:
            return guess

def playAgain():
                   print('Would you like to try again soldier (Yes or No)')
                   return input().lower().startswith('y')

print('BUNKER BARRAGE SIMULATOR 9000')
ShotsMissed = ''
ShotsHit = ''
GoodShots = getRandomNo(Kills)
gameisDone = False

while True:
    displayBoard(BunkerPics , ShotsMissed , ShotsHit , GoodShots)

    guess = getGuess(ShotsMissed + ShotsHit)

    if guess in GoodShots:
        ShotsHit = ShotsHit + guess
        
        foundAllshots = True
        for i in range(len(ShotsHit)):
            if GoodShots[i] not in ShotsHit:
                foundAllshots = False
                break
            if foundAllshots:
                print('Good Shot')
                gameIsDone = True
        else:
            ShotsMissed = ShotsMissed + guess
            
            if len(ShotsMissed) == len(BunkerPics) - 1:
                displayBoard(BunkerPics, ShotsMissed, ShotsHit, GoodShots)
                print('You have run out of guesses!\nAfter ' + str(len(ShotsMissed)) + ' missed guesses and ' + str(len(ShotsHit)) + ' correct guesses, You Died')
                gameIsDone = True
            if gameIsDone:
                if playAgain():
                    ShotsMissed = ''
                    GoodShots = ''
                    gameIsDone = False
                    GoodShots = getRandomNo(Kills)
                else:
                   break
 i hope you can see that every shot is supposed to either contribute to the answer, or go into the missed shots text line, i cannot figure out what is going on with it, but try to run and i think you can see the issues


RE: Need Help debugging program - Larz60+ - Dec-15-2016

Quote:but try to run and i think you can see the issues

It's your job to explain which of the issues (which you provide, we don't generate) that you want a response on.


RE: Need Help debugging program - nilamo - Dec-16-2016

Is the problem that you're using while True: but never break out of the loop? You do have a gameIsDone that you set and re-set, maybe you should loop over that instead?


RE: Need Help debugging program - ToastyCoder - Dec-19-2016

(Dec-16-2016, 09:40 PM)nilamo Wrote: Is the problem that you're using while True: but never break out of the loop?  You do have a gameIsDone that you set and re-set, maybe you should loop over that instead?

what do you mean, sorry i am really uneducated in this whole thing


RE: Need Help debugging program - nilamo - Dec-19-2016

You have a while loop that looks like "while True:". That means the loop will continue forever. Is it supposed to continue forever?


RE: Need Help debugging program - ToastyCoder - Dec-19-2016

(Dec-19-2016, 07:03 PM)nilamo Wrote: You have a while loop that looks like "while True:".  That means the loop will continue forever.  Is it supposed to continue forever?

No, but i do not know how to change it


RE: Need Help debugging program - nilamo - Dec-19-2016

Ok, try changing it to while not gameIsDone:.