lundi 12 janvier 2015

how to .format a randomint/randomchoice in python

First off im new to programming. SO now that thats out of the way ill get straight to the point. Im trying to pull a int from a randint function. For example: `def wiz(): wizard = random.randint(3, 5) health = 10 while True: cmd = input("atk or def? ") if cmd == 'atk': wizard = wizard - 1 print("You hit the Wizard for 1 damage. The Wizard has {} health left".format(wizard))



if wizard <= 0:
print("You defeat the wizard!")
break
**while cmd == 'atk':
health = health - random.randint(2, 3)
print("The Wizard hits you for {} damage.".format(randint))
print("You now have {} health!".format(health))
break**
if health <= 0:
print("You were defeated! Better luck next time!")
break

else:
if cmd == 'def':
print("You defend this round healing your health for 1 hp.")
health = health + 1
print("You now have {} health.".format(health))

continue


` In the while loop im doing health = health - random.randint(2, 3). Followed by your usual print statement with a .format at the end. I am just not sure what to put in the parenthesis after format. If anyone has any type of input that would be great. THANK!





Aucun commentaire:

Enregistrer un commentaire