[Tutor] Python Help - How to end program

2010-07-28 Thread Jason MacFiggen
Python keeps looping when it gets past the int 0, how do I end the program
when it the int 0 or > 0.

my_hp = 50
mo_hp = 50
my_dmg = random.randrange(1, 20)
mo_dmg = random.randrange(1, 20)
endProgram = end()
while True:
if mo_hp < 0:
print "The Lich King has been slain!"
elif my_hp < 0:
print "You have been slain by the Lich King!"
if mo_hp <= 0:
endProgram
else my_hp <= 0:
endProgram
else:
print "Menu Selections: "
print "1 - Attack"
print "2 - Defend"
print
choice = input ("Enter your selection. ")
choice = float(choice)
print
if choice == 1:
mo_hp = mo_hp - my_dmg
print "The Lich King is at ", mo_hp, "Hit Points"
print "You did ", my_dmg, "damage!"
print
my_hp = my_hp - mo_dmg
print "I was attacked by the lk for ", mo_dmg," damage!"
print "My Hit Points are ", my_hp
print
elif choice == 2:
mo_hp = mo_hp - my_dmg / 2
print "The Lich King is at", mo_hp, "Hit Points"
print "you did ", my_dmg / 2, "damage!"
print
my_hp = my_hp - mo_dmg
print "I was attacked by the lk for ", mo_dmg," damage!"
print "My Hit Points are ", my_hp
print
-Thank you
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python - RPG Combat System

2010-07-30 Thread Jason MacFiggen
I am have trouble figuring out how to make my program stop at 0 hit
points if I run it, it always goes into the negative hitpoints...

So my question is how do I make this program end at exactly 0 hit points
every time instead of going over?

and also, what can I do instead of writing print so many times?

import random
my_hp = 50
mo_hp = 50
my_dmg = random.randrange(1, 20)
mo_dmg = random.randrange(1, 20)
while True:
if mo_hp < 0:
print "The Lich King has been slain!"
elif my_hp < 0:
print "You have been slain by the Lich King!"
if mo_hp <= 0:
break
elif my_hp <= 0:
break
else:
print "Menu Selections: "
print "1 - Attack"
print "2 - Defend"
print
choice = input ("Enter your selection. ")
choice = float(choice)
print
if choice == 1:
mo_hp = mo_hp - my_dmg
print "The Lich King is at ", mo_hp, "Hit Points"
print "You did ", my_dmg, "damage!"
print
my_hp = my_hp - mo_dmg
print "I was attacked by the lk for ", mo_dmg," damage!"
print "My Hit Points are ", my_hp
print
elif choice == 2:
mo_hp = mo_hp - my_dmg / 2
print "The Lich King is at", mo_hp, "Hit Points"
print "you did ", my_dmg / 2, "damage!"
print
my_hp = my_hp - mo_dmg
print "I was attacked by the lk for ", mo_dmg," damage!"
print "My Hit Points are ", my_hp
print
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Simple Python Program

2010-07-30 Thread Jason MacFiggen
Can anyone tell me how to fix the errors I am getting if possible? I'm quite
new and so confused...

also how do I display the winner under the displayInfo function?

import random

def main():
print

playerOne, playerTwo = inputNames(playerOne, PlayerTwo)

while endProgram == 'no':

endProgram == no
playerOne = 'NO NAME'
playerTwo = 'NO NAME'

winnerName = rollDice(p1number, p2number, playerOne, playerTwo,
winnerName)
winnerName = displayInfo

endProgram = raw_input('Do you want to end program? (Enter yes or
no): ')

def inputNames(playerOne, PlayerTwo):

p1name = raw_input("Enter your name.")
p2name = raw_input("Enter your name.")
return playerOne, playerTwo

def random(winnerName):

p1number = random.randint(1, 6)
p2number = random.randint(1, 6)

if p1number > p2number:
playerOne = winnerName
elif p1number < p2number:
playerTwo = winnerName
else p1number == p2number:
playerOne, playerTwo = winnerName

def displayInfo():

#how do I display winner?

main()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sys.exit help

2010-08-01 Thread Jason MacFiggen
I was wondering how can I change sys.exit so if you use command line to run
the program. it prompts a message asking if the user wants to exit instead
of automatically just exiting?

import random
import sys
my_hp = 50
mo_hp = 50
menu1 = """
Menu Selections:
1 - Attack
2 - Defend
3 - Help
4 - Exit
"""
print menu1
while True:
my_dmg = random.randrange(1, 20)
mo_dmg = random.randrange(1, 20)

choice = input ("\nEnter your selection. ")
choice = float(choice)
print
if choice == 1:
mo_hp = mo_hp - my_dmg
if mo_hp <= 0:
print "Iris is at 0 Hit Points!\nYOU HAVE SLAIN IRIS!"
sys.exit(0)
elif mo_hp > 0:
print
"-"
print "Iris is at %s Hit Points\nYou did %s damage\n" %
(mo_hp, my_dmg)
my_hp = my_hp - mo_dmg
if my_hp <= 0:
print "Your Hit Points are 0!\nYOU HAVE BEEN SLAIN BY Iris!"
sys.exit(0)
elif my_hp > 0:
print name,"was attacked by Iris for %s damage!\nMy Hit
Points are %s" % (mo_dmg, my_hp)
print
"-"
else:
print menu1


elif choice == 2:
mo_hp = mo_hp - my_dmg / 2
if mo_hp <= 0:
print "The Lich King is at 0 Hit Points!\nYOU HAVE SLAIN
IRIS!"
sys.exit(0)
elif mo_hp > 0:
print
"-"
print "The Lich King is at %s Hit Points\nYou did %s
damage\n" % (mo_hp, my_dmg)
my_hp = my_hp - mo_dmg / 2
if my_hp <= 0:
print "Your Hit Points are 0!\nYOU HAVE BEEN SLAIN BY IRIS!"
sys.exit(0)
elif my_hp > 0:
print name,"was attacked by the Iris for %s damage!\nMy Hit
Points are %s" % (mo_dmg, my_hp)
print
"-"
else:
print menu1

elif choice == 3:
print """
-
Attack = Attack for 100% of damage.
Defending = Attack for 50% of damage and endure 50% of damage.
-
"""
elif choice == 4:
sys.exit(0)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Menu not working properly

2010-08-02 Thread Jason MacFiggen
My problem is choice 3. Exit, if you select no or put an invalid answer...
It will run menu1... but then it runs
name = raw_input ("Enter your character name. ")
print "Your character name is:", name

How can i make it so it prints menu1 like normal... then asks you to enter
your selection again?
instead of running the above code.

-Thank you

import sys

def menu():
menu1 = """
Pick A Class From The Menu or choose Exit.
1. Warrior
2. Mage
3. Exit
"""
print "Welcome to Iris's Last Breath"
print menu1
characterChoice = input ("Enter your choice. ")
print

if characterChoice == 1:
print """

*Place Holder*

"""

elif characterChoice == 2:
print "Currently under construction.\nPlease choose again."
print menu1
elif characterChoice == 3:
endProgram = raw_input ("Do you want to end program? yes or no ")
if endProgram == "yes":
sys.exit(0)
elif endProgram == "no":
print menu1
else:
print "\nInvalid Command:\nSelect from the menu again.\n"
print menu1

print
name = raw_input ("Enter your character name. ")
print "Your character name is:", name
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor