Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么不是';我的变量没有被定义吗?_Python - Fatal编程技术网

Python 为什么不是';我的变量没有被定义吗?

Python 为什么不是';我的变量没有被定义吗?,python,Python,这是我的密码。 它给了我一个错误无法定义玩家的攻击。earth 为什么?我定义了它。这里有什么问题? 我使用的是python 3.4.3,答案很简单,因为变量名中不能有“.”。这将指向类中的属性 您可以在此处找到有关允许的字符和命名规则的更多详细信息:请回答您的问题并包含回溯的全文。使用{}代码格式化按钮正确格式化代码。什么是playerAttack?这是一节课吗?它已经有earth字段了吗?我是python新手,所以我知道的不多。这是所有的代码我们不想要“所有的代码”;创建一个我只有13岁,所

这是我的密码。 它给了我一个错误
无法定义玩家的攻击。earth
为什么?我定义了它。这里有什么问题?
我使用的是python 3.4.3,答案很简单,因为变量名中不能有“.”。这将指向类中的属性


您可以在此处找到有关允许的字符和命名规则的更多详细信息:

请回答您的问题并包含回溯的全文。使用
{}
代码格式化按钮正确格式化代码。什么是
playerAttack
?这是一节课吗?它已经有
earth
字段了吗?我是python新手,所以我知道的不多。这是所有的代码我们不想要“所有的代码”;创建一个我只有13岁,所以我在这里是新的天啊
# players stats and elements
player_health = 100
player_attack.earth = 20
player_attack.air =10
player_attack.fire = 15
player_attack.water = 12
ogre_health = 75
ogre_attack = 15

# main code
player_name = input('What is your name, Guardian? ')

print('Hello ' + player_name + ' the Guardian')

player_element = input('Would you like to be the Guardian of Air, Earth, Fire or Water? ')

if player_element == 'Air':
    print('You have been granted the powers of the Air, Guardian.\
You now have the powers of the Wind and Sky.')

if player_element == 'Earth':
    print('You have been granted the powers of the Earth, Guardian.\
You now have the powers of the Earth.')

if player_element == 'Fire':
    print('You have been granted the powers of Fire, Guardian.\
You now have the powers of Fire. Do not destroy as you wish.')

if player_element == 'Water':
    print('You have been granted the powers of Water, Guardian.\
You now have the powers to control the oceans and water.')

print('There is an enemy in the distance! What do you do?')

player_action = input('What do you do ' + player_name + '? ' + 'Type A to attack ')
if player_action == 'A':
   enemy_health = enemy_health - power

print('The enemy\'s health is at ' + str(enemy_health) + ' Keep attacking!')

player_action = input('What do you do ' + player_name + '? ' + 'Type A to attack ')
if player_action == 'A':

    if player_element == 'Water':
        ogre_health = ogre_health - player_attack.water

print('The enemy\'s health is at ' + str(ogre_health) + ' Keep attacking!')