Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Can you find any bugs in this program? - Python Text Game
New Posts  All Forums:Forum Nav:

Can you find any bugs in this program? - Python Text Game

post #1 of 5
Thread Starter 
Hey! I'm currently learning Python with the Learn Python The Hard Way free HTML version. So far, I'm doing pretty good and am on exercise 36. I finished the exercise and have two files, the main story file, and the module file. The code for the two files are of the following.

main file
Code:
from ex36functions import *
def sescape():
    print "> While trying to escape, you get surrounded by a massive number of guards."
    print "> What do you want to do?"
    print "> 1 Surrender and accept punishment > 2 Fight your way out > 3 Make up a bluff"
    c = digit(raw_input("> NUMBER: "), [1, 2, 3])
    if c == 1:
        death("You are an idiot!")
    if c == 2:
        death("You think you can fight your way through that many strong people!")
    if c == 3:
        print "> You threaten to blow yourself and the prison up if they do not let you go."
        print "> Fortunately, the guards believe you and let you free.\n> YOU WIN!"
def help():
    print "> While the guards are distracted, you have an opportunity to escape."
    print "> What do you want to do?"
    print "> 1 Eliminate guards and try to escape > 2 Nothing"
    c = digit(raw_input("> NUMBER: "), [1, 2])
    if c == 1:
        sescape()
    if c == 2:
        death("You are an idiot!")
def sword():
    print "> It turns out that the bars are made of diamond and coated with steel,"
    print "> so the sword snaps in half and flies off in the other direction."
    print "> Unfortunately, \"the other direction\" leads to your cellmate, killing him."
    print "> What do you want to do?"
    print "> 1 Hide corpse under bed > 2 Call guards for help > 3 Try to heal corpse"
    c = digit(raw_input("> NUMBER: "), [1, 2, 3])
    if c == 1:
        death("Guard notices the corpse under the bed and you receive the death penalty!")
    if c == 2:
        help()
    if c == 3:
        death("You go insane when you realize you can not revive the corpse!")
def fescape():
    print "> The guards find out you are outside of your cell and are hunting you down."
    print "> They find you in the back of the prison and have you cornered and trapped."
    print "> What do you want to do?"
    print "> 1 Jump off the cliff > 2 Run away > 3 Surrender and accept punishment"
    c = digit(raw_input("> NUMBER: "), [1, 2, 3])
    if c == 1:
        death("Even though that is commonly done in movies, this isn't a movie, it's a game!")
    if c == 2:
        print "> Well, that is better than all of your other options.\n> YOU WIN!"
    if c == 3:
        death("You are an idiot!")
def dodge():
    print "> Multiple fireballs hit the same place on the wall and burn a hole through it."
    print "> What do you want to do?"
    print "> 1 Escape through the burnt hole > 2 Nothing"
    c = digit(raw_input("> NUMBER: "), [1, 2])
    if c == 1:
        fescape()
    if c == 2:
        death("You are an idiot!")
def fire():
    print "> The bars are heat resistant, so the fireballs you shot come back at you."
    print "> What do you want to do?"
    print "> 1 Try to dodge fireballs > 2 Reflect fireballs > 3 Try to absorb fireballs"
    c = digit(raw_input("> NUMBER: "), [1, 2, 3])
    if c == 1:
        dodge()
    if c == 2:
        print "> One of the fireballs somehow get outside of the cell and hits a guard."
        death("You receive the death penalty for killing a guard!")
    if c == 3:
        death("You think you can absorb that much energy in the state you are in right now!")
print "> You are a freedom fighter imprisoned in a cell for opposing the government."
print "> What do you want to do?"
print "> 1 Cut bars with your sword > 2 Melt bars with your pyrokinesis powers"
c = digit(raw_input("> NUMBER: "), [1, 2])
if c == 1:
    sword()
if c == 2:
    fire()

module file
Code:
def digit(n, args):
    while not n in ["%d" % i for i in args]:
        print "> Please enter a VALID integer!"
        n = raw_input("> NUMBER: ")
    return int(n)
def death(n):
    print "> %s\n> YOU LOSE!" % n

I have been working on the exercise for a while and I think I have eliminated all possible bugs. Now, I know that's a pretty big claim to make, but I can't find any bugs. So ... can any of you please go through my code and try to find any bugs. Both of the files are in the same folder, so don't worry about any importing bugs. Thanks in advance. Also, I quickly typed this, so sorry for any formatting/spelling errors (in the post, of course, not the code biggrin.gif).
post #2 of 5
Thread Starter 
bump?
post #3 of 5

If it's working correctly, don't try to fix it. Of course with some things you write, you may be able to improve performance in certain cases, but for the most part if you write something, debug it, and have a working implementation, just move on. Good luck with Python!

Mini Trendy
(0 items)
  
Reply
Mini Trendy
(0 items)
  
Reply
post #4 of 5
Quote:
Originally Posted by trendy View Post

If it's working correctly, don't try to fix it. Of course with some things you write, you may be able to improve performance in certain cases, but for the most part if you write something, debug it, and have a working implementation, just move on. Good luck with Python!

I disagree. I think it's good practice to thoroughly test your code and have a desire to fix bugs. Not wanting to find bugs can lead to security vulnerabilities and data loss due to software crashing (obviously that's not an issue here - but testing is a good habit to get into)
post #5 of 5
Thread Starter 
Quote:
Originally Posted by trendy View Post

If it's working correctly, don't try to fix it. Of course with some things you write, you may be able to improve performance in certain cases, but for the most part if you write something, debug it, and have a working implementation, just move on. Good luck with Python!

Quote:
Originally Posted by Plan9 View Post

I disagree. I think it's good practice to thoroughly test your code and have a desire to fix bugs. Not wanting to find bugs can lead to security vulnerabilities and data loss due to software crashing (obviously that's not an issue here - but testing is a good habit to get into)

Thanks for both of your replies! However, I have to say that I agree with Plan9's opinion more. Anyways, I asked my little brother to play the game several times, and no matter what he typed in as input didn't crash the game, so I think it's safe to assume that it's bug free.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Can you find any bugs in this program? - Python Text Game