Bottom Page

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
Quote
#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 :)
Quote
#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.
Quote
#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
Quote
#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.
micseydel likes this post
Quote
#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?
Quote
#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
Quote
#8
You have a while loop that looks like "while True:". That means the loop will continue forever. Is it supposed to continue forever?
Quote
#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
Quote
#10
Ok, try changing it to while not gameIsDone:.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  cProfile debugging fakka 0 63 Jul-10-2019, 01:41 PM
Last Post: fakka
  Debugging in VS code kw42chan 0 90 Jul-02-2019, 02:06 PM
Last Post: kw42chan
  Newb question: Debugging + Linting Python in Visual Studio Code Drone4four 1 155 Apr-15-2019, 06:19 AM
Last Post: perfringo
  Debugging adam10e10 3 278 Apr-04-2019, 07:53 AM
Last Post: j.crater
  I need help debugging a class. knightwatch 2 252 Jan-16-2019, 02:28 AM
Last Post: stullis
  Debugging Python Astrikor 1 301 Dec-04-2018, 12:27 PM
Last Post: Larz60+
  python 'SMTP debugging server' not starting local error pcsailor 1 322 Nov-26-2018, 10:13 PM
Last Post: micseydel
  Debugging inside a thread with Python 2.3.4 zerajera 0 280 Nov-21-2018, 01:43 PM
Last Post: zerajera
  Debugging a seg fault tidymax 1 342 Oct-31-2018, 02:58 PM
Last Post: ichabod801
  Python debugging local os Baggelhsk95 1 342 Oct-18-2018, 10:11 AM
Last Post: Gribouillis

Forum Jump:


Users browsing this thread: 1 Guest(s)