Posts: 5
Threads: 1
Joined: Dec 2016
Posts: 2,342
Threads: 62
Joined: Sep 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 :)
Posts: 470
Threads: 29
Joined: Sep 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.
Posts: 5
Threads: 1
Joined: Dec 2016
Dec-15-2016, 06:41 PM
(This post was last modified: Dec-15-2016, 07:11 PM by Mekire.)
(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
Posts: 12,030
Threads: 485
Joined: Sep 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.
Posts: 3,458
Threads: 101
Joined: Sep 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?
Posts: 5
Threads: 1
Joined: Dec 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
Posts: 3,458
Threads: 101
Joined: Sep 2016
You have a while loop that looks like "while True:". That means the loop will continue forever. Is it supposed to continue forever?
Posts: 5
Threads: 1
Joined: Dec 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
Posts: 3,458
Threads: 101
Joined: Sep 2016
Ok, try changing it to while not gameIsDone: .
|