[Tutor] Python Help - How to end program
Benjamin Castillo
bsc26 at yahoo.com
Thu Jul 29 06:11:09 CEST 2010
Jason
Are you trying to prevent negative numbers?
Ben
--- On Wed, 7/28/10, Jason MacFiggen <jmacfiggen at gmail.com> wrote:
From: Jason MacFiggen <jmacfiggen at gmail.com>
Subject: [Tutor] Python Help - How to end program
To: tutor at python.org
Date: Wednesday, July 28, 2010, 9:01 PM
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
-----Inline Attachment Follows-----
_______________________________________________
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100728/13bdf689/attachment-0001.html>
More information about the Tutor
mailing list