+ 1

Using instances of classes as variables in a function?

The following is a code that provides me with a syntax errors when I run it: class HearthStone(): '''Models a hearthstone card''' def __init__(s, name, mana, attack, health): s.name = name s.mana = mana s.attack = attack s.health = health def show_info(s): ''' Displays basic card info ''' print( 'Name: ' + str(s.name.title())+ '\nMana cost: ' + str(s.mana) + '\nHealth: ' + str(s.health) + '\nAttack: ' + str(s.attack) ) def attack(s, target): '''Lets try this again''' print(s.name.title() + ' [' + str(s.health) + '/' + str(s.attack) + '] ' + ' V.S. ') print(s.target.name.title() + ' ['+str(target.s.health) + '/'+str(target.s.attack) + ']') chillwind_yeti = HearthStone('chillwind yeti', 4, 4, 5) chillwind_yeti.show_info() carrion_grub = HearthStone('carrion grub', 3, 2, 5) chillwind_yeti.attack(carrion_grub) It says the syntax error is on the line where I define the variable 'carion_grub' and I was curious as to what I was doing wrong, and how to use other instances of a class in the function of another instance in general. Thanks!

14th Jan 2017, 10:55 PM
flarphengarg
flarphengarg - avatar
1 Resposta
0
Well caringrub is not defined on the same line as the class or something if you could put what syntax that would be helpful Python is very particular about lines it reads it horizontally so make sure to do that.
15th Jan 2017, 1:27 AM
Nate