The example code that @
buran posted from the URL you provided has several syntax errors and several logic errors. Your first job is to get the code to compile without any errors or warnings with as few changes as possible. The following list should help you get started:
a. The use of 'global' is discouraged.
b. Variable names should be lower case (e.g. comp_health instead of compHealth. NOTE: CASE MATTERS.
c. Indentation matters
d. Colons at the end of if .. elif .. else statements
e. Use of unneeded parentheses is discouraged
f. 'or if' should be 'elif'
g. print ("Do you wish to attack") should probably by choice = input("Do you wish to attack?")
h. Put lots of print statements like print("battleComp(): playerHealth = {} compHealth = {}.".format(playerHealth, compHealth)) so you know what is going on during testing.
The following code snippets should help you with the notes above.
Use of global (not recommended - see alternative example below):
def battleResultExampleUsingGlobalWhichShouldBeDiscouraged():
global compHealth
global playerHealth
if compHealth == 0:
print ("Your hands are slick with his blood. ")
print ("You have slayen your opponent." )
elif playerHealth == 0:
print ("Your opponent stands over you and drives his sword into your chest. ")
print ("You have died! ")
Alternative to use of global:
def example(player_health, opponent_health):
player_health = 33
opponent_health = 66
return player_health, opponent_health
player_health = 99
opponent_health = 98
print("before: player_health = {} opponent_health = {}.".format(player_health, opponent_health))
player_health, opponent_health = example(player_health, opponent_health)
print("after: player_health = {} opponent_health = {}.".format(player_health, opponent_health))
Main body of program example. There are better ways to do the loop, but this should help you get started.
playAgain = "yes"
while playAgain == "yes" or playAgain == "y":
battleIntro()
### unsure of what needs to go here ###
battlePlayer()
battleComp()
battleResult()
print ("Do you want to play again?")
playAgain = input()
Lewis