I am new in this website so sorry if I am doing something absurd or against rules but I have a question.
I am new to Python and programming. I am learning Python and when I am exercising I encountered and Error. I searched for solutions here but most of them was above my level that I couldn't understand.
Please try to answer in a way a beginner can understand, thank you.
Here is the code and the Error I get is; 'AttributeError: 'tuple' object has no attribute 'print''
Thanks for any help.
import random
class Enemy:
name = "Enemy"
health = 100
damage = 5
ammo = 20
def __init__(self,name,health,damage,ammo):
self.name = name
self.health = health
self.damage = damage
self.ammo = ammo
def properties(self):
print("Properties: ")
print("Name: ",self.name)
print("Health: ",self.health)
print("Damage: ",self.damage)
print("Ammo: ",self.ammo)
def attack(self):
print(self.name + " is attacking!")
ammo_spent = random.randrange(1,10)
print(str(ammo_spent) + " ammo spent.")
self.ammo -= ammo_spent
return (ammo_spent,self.damage)
def getattacked(self,ammo_spent,damage):
print ("I've been shot!")
self.health -= (ammo_spent * damage)
def is_ammo_depleted(self):
if (self.ammo <= 0):
print (self.name + "'s ammo depleted.")
return True
return False
def check(self):
if (self.health <= 0):
print("YOU DIED.")
Enemies = []
i = 0
while (i < 9):
randomhealth = random.randrange(125,300,25)
randomdamage = random.randrange(25,100,25)
randomammo = random.randrange(20,200,20)
new_enemy = ("Enemy" + str(i+1),randomhealth,randomdamage,randomammo)
Enemies.append(new_enemy)
i += 1
for Enemy in Enemies:
Enemy.properties()