Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need Help debugging program
#1
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
Reply
#2
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 :)
Reply
#3
(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.
Reply
#4
(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
Reply
#5
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.
Reply
#6
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?
Reply
#7
(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
Reply
#8
You have a while loop that looks like "while True:". That means the loop will continue forever. Is it supposed to continue forever?
Reply
#9
(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
Reply
#10
Ok, try changing it to while not gameIsDone:.
Reply


Forum Jump:

User Panel Messages

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