'type' object is not subsrcriptable python - python

i cant tell what this error is telling me it says the error is on line 64 of this code if possible can you please check too see if my code has additional errors thnx so much guys i tried multiple things and couldn't get it to work.
Traceback (most recent call last):
File "C:\Users\AdamFeffer\triviacrack.py", line 93, in <module>
QnA2()
File "C:\Users\AdamFeffer\triviacrack.py", line 64, in QnA2
if uanswer == quest[whichq].rA:
TypeError: 'type' object is not subscriptable
import random
import time
# Flase = playerone true player 2
wt = False
score = 0
kg = True
kgt = True
playerov = False
class playerone(object):
def __init__(self, name, score, victory):
self.name = name
self.score = score
self.victory = victory
class playertwo(object):
def __init__(self, name, score, victory):
self.name = name
self.score = score
self.victory = victory
class quest(object):
def __init__(self, q, a1, a2, a3, a4, rA):
self.question = q
self.answer1 = a1
self.answer2 = a2
self.answer3 = a3
self.answer4 = a4
self.realanswer = rA
### Questions ###
q1 = quest("The largest artery in the human body helps carry blood from the heart throughout the body. What is it?","Aorta", "your mom haha lol", "Jugular","Borta", 1)
q2 = quest("In the year 1900 in the U.S. what were the most popular first names given to boy and girl babies?", "William and Elizabeth", "Joseph and Catherine", "John and Mary","George and Anne", 3)
q3 = quest("When did the Liberty Bell get its name?", "when it was made, in 1701", "when it rang on July 4, 1776", "in the 19th century, when it became a symbol of the abolition of slavery", " none of the above", 3)
#################
#questoin arrays
questions = [q1, q2, q3]
qt = ["science", "history", "sports", "entertainment", "art"]
def QnA():
global kg
global oneplayer
global score
global player
p = player
whichq = random.randint(0, 4)
print(questions[whichq].question)
print(questions[whichq].answer1 + " (1)")
print(questions[whichq].answer2 + " (2)")
print(questions[whichq].answer3 + " (3)")
print(questions[whichq].answer4 + " (4)")
uanswer = int(input("answer "))
if uanswer == quest[whichq].realanswer:
score = score + 1
print ("YA NEXT QUESTION")
else:
print(p + "you didn't get it right")
kg = False
def QnA2():
global kgt
global wt
whichq = random.randint(0, 4)
print(questions[whichq].question)
print(questions[whichq].answer1 + " (1)")
print(questions[whichq].answer2 + " (2)")
print(questions[whichq].answer3 + " (3)")
print(questions[whichq].answer4 + " (4)")
uanswer = int(input("answer "))
if uanswer == quest[whichq].rA:
if wt == false:
playerone.score = playerone.score + 1
else:
playertwo.score = playertwo.score + 1
if wt == True:
wt = False
else:
wt = True
def timer():
timer = 60
while timer > 0:
print (timer)
timer = timer - 1
time.sleep(1)
print ("times up!!")
oot = int(input("(1) one player sudden death or (2) 2 player: "))
if oot == 1:
oneplayer = True
player = input("player name: ")
while kg == True:
QnA()
print("sorry your score was " + (score) + "gg")
else:
playero = input("player 1 name: ")
playert = input("player 2 name: ")
playerone = playerone(playero, 0, False)
playertwo = playertwo(playert, 0, False)
while kgt == True:
QnA2()

solution
Line 64: if uanswer == questions[whichq].realanswer:
Whats wrong
You are attempting to use quest which is a class instead of the questions list. quest can not be subscripted with [] but questions can, because it is a list.
In addition, you are trying to use rA which is an argument to the __init__ function. You can not use this argument outside of __init__. Instead you need to use the member variable realanswer :)

Related

how i create new object to use on turn based battle game 3units vs 3 ai units

Your team has been assigned to develop a console or GUI turn-based battle game. The game allows player setup his/her team which made up of a numbers of units (default is 3). Each unit has a name, health point (HP), attack point (ATK), defence point (DEF), experience (EXP) and a rank. On top of that, a unit can be either a Warrior or Tanker which having different strength in different range for ATK and DEF point. The initial value for each attribute point are describe in the details requirement in Part A – Table 1.
The game will then setup another team belongs to AI which made up of same number of unit as the player’s team. The type of unit will be assigned randomly by chances. The name of each unit will be specify by the player while the name of each unit for AI team will be defined with prefix with “AI” follow by 2 random digits i.e. AI87.
A player can select a unit from his/her team and attack the other unit (the target) in the opponent / AI team. Unit which are severely damaged (i.e. HP equals to less than 0) will be defeated and removed from the team. The team (player / AI) which destroy all the opponent units first will be declared as winner of the game.
enter code here
class GameCharacter:
char_name = ""
char_type = ""
__hp = 0
__atk = 0
__def = 0
__rank = 0
def __init__(self, char_type, char_name):
self.char_type: str = char_type
self.char_name: str = char_name
if char_type == "Warrior":
self.setup_warrior()
elif char_type == "Tanker":
self.setup_tanker()
def setup_warrior(self):
self.__hp = 100
self.__atk = 20
self.__def = 6
self.__rank = 1
return [self]
def setup_tanker(self):
self.__hp = 100
self.__atk = 8
self.__def = 9
self.__rank = 1
return [self]
def get_attack(self):
return self.__atk
def get_health(self):
return self.__hp
def __str__(self):
text = "Character type:{},name:{}".format(self.char_type, self.char_name)
return text
enter code here
import game_setting
import random
rounds = 1
count = 0
gs = game_setting.GameCharacter.__init__(char_type, char_name)
player_team = []
ai_bot = []
def detail_ai():
print(ai_bot)
def detail_player():
print(player_team)
def details_all():
print(player_team)
print(ai_bot)
def main():
get_name = ""
j = random.randint(1, 2)
ch = ""
i: int
types = ""
for i in range(1, 4):
get_name = (input("Choose character name:"))
ch = (input("Choose character type [w/t]:")).lower()
if ch == 'w' and get_name != "":
types: str = "Warrior"
player_team.append(types)
player_team.append(get_name)
print("character", i, ":", types, "Name:", get_name)
elif ch == 't':
types: str = "Tanker"
player_team.append(self.types)
print("character", i, ":", types, "Name:", get_name)
else:
print("Wrong value ")
# =======================================Ai Bot name=================================================
for i in range(1, 4):
if ch == "w" and j != j:
ch: str = "Warrior"
ai_bot.append(ch)
elif ch == "t" and j != j:
types: str = "Tanker"
player_team.append(types)
else:
print("Wrong value ")
k = str(random.randint(10, 99))
if get_name != get_name:
get_name: str = "AI" + k
ai_bot.append(get_name)
else:
print("Done setting.")
print("character", i, " : ", types, "Name:", get_name)
show_name: str = ""
show_type: str = ""
main()

Working on my first real game in Python, But I've Ran into a few problems

While coding my game, I've ran into problems when running it. For example, the zombie attack doesn't come out correctly, when using the store the gold value and health value do not update. When running the battle part, the first time the zombie has less health, then more health, and more damage. I don't know what I've messed up on. Any help/tips?
import time
import sys
import random
cls = ("\n"*100)
class Mage:
def __init__(self):
self.maxhp = 50
self.attack = 3.33
self.name = "Mage"
class Warrior:
def __init__(self):
self.maxhp = 70
self.attack = 2.5
self.name = "Warrior"
class Thief:
def __init__(self):
self.maxhp = 35
self.attack = 5
self.name = "Thief"
class Zombie:
def __init__(self):
self.maxhp = 10
self.attack = 1
self.name = "Zombie"
def heal(character_health):
if character_health < character_health:
character_health += 5
print("Healed. Health is now " + character_health + " +5.")
time.sleep(2)
else:
print("No healing available.")
time.sleep(2)
def battle(character_health, character_attack, monster_health, monster_attack, gold):
while True:
character_health_max = character_health
monster_name = "Zombie"
choice1 = input("\nPress 1 to Attack: ")
if choice1 == "1":
monster_health -= character_attack
print("\n" + str(monster_name) + "'s health is now " + str(monster_health))
time.sleep(1)
character_health -= monster_attack
print("\nThe hero's health is now " + str(character_health))
time.sleep(1)
if character_health <= 0:
print("\nThe hero is dead.")
sys.exit("\nThe End")
if monster_health <= 0:
print("\nThe monster is dead.")
time.sleep(2)
print("Your gold has increased by: 5")
gold += 5
monster_health = 10
character_health = character_health_max
time.sleep(2)
menu_list(character_health, character_attack, monster_health, monster_attack, gold)
def store(gold, character_health):
print("\nWelcome to my shop of wonders! My name is Hanz, what can I aid you with today? We have...\nPotions: [1.] EEK")
buy = input("\nWhat will it be? ")
if gold < 5:
print("Sorry, you don't have any gold!")
time.sleep(2)
if buy == "1" and gold >= 5:
print("\nYou now own the Potion EEK! Health increased by 5!")
character_health += 5
gold -= 5
time.sleep(2)
def menu_list(character_health, character_attack, monster_health, monster_attack, gold):
while True:
print(cls)
menu = input("---> Fight [1.] \n---> Heal [2.] \n---> Store [3.] \n---> Quit [4.] \n---> Gold: " + str(gold) + " \n---> ")
if menu == "4":
sys.exit()
if menu == "2":
heal(character_health)
if menu == "1":
battle(character_health, character_attack, monster_attack, monster_health, gold)
if menu == "3":
store(gold, character_attack)
if menu == "Gold":
print("\nNot valid hackerman.")
time.sleep(1)
class Main:
print(cls)
name = input("What is your name: ")
character = input("\nChoose your class: \n----------------- \nMage [1.] \nWarrior [2.] \nThief [3.] \n---> ")
if character == "1":
character_health = Mage().maxhp
print("\nHealth " + str(character_health))
character_attack = Mage().attack
print("\nAttack " + str(character_attack))
character_name = Mage().name
print("\nClass " + str(character_name))
time.sleep(3)
monster_health = Zombie().maxhp
monster_attack = Zombie().attack
gold = 0
menu_list(character_health, character_attack, monster_health, monster_attack, gold)
if character == "2":
character_health = Warrior().maxhp
print("\nHealth " + str(character_health))
character_attack = Warrior().attack
print("\nAttack " + str(character_attack))
character_name = Warrior().name
print("\nClass " + str(character_name))
time.sleep(3)
monster_health = Zombie().maxhp
monster_attack = Zombie().attack
gold = 0
menu_list(character_health, character_attack, monster_health, monster_attack, gold)
if character == "3":
character_health = Thief().maxhp
print("\nHealth " + str(character_health))
character_attack = Thief().attack
print("\nAttack " + str(character_attack))
character_name = Thief().name
print("\nClass " + str(character_name))
time.sleep(3)
monster_health = Zombie().maxhp
monster_attack = Zombie().attack
gold = 0
menu_list(character_health, character_attack, monster_health, monster_attack, gold)
if __name__ == '__main__':
Main()
I think this is a good time to go over what happens when you pass variables to functions in Python.
Firstly, everything in Python is an object! Primitives too (numbers are wrapped as an object in Python). Every class of objects inherit from the object class in Python.
Now, what happens when you pass a primitive to a function and change the value?
To illustrate:
def foo(a):
a = 5
b = 1
foo(b)
print(b) # b is still 1! Some objects in Python are immutable including integers, strings, and booleans.
Now I suspect your gold and health values aren't changing because you're passing in immutable objects which cannot be changed!
How to resolve?
You want to pass in a mutable object! Instead of passing an integer object (which is immutable) for a character's health, pass in the character object (which is mutable). You can set the new health of that character object.
To illustrate:
class Warrior:
def __init__(self):
self.maxhp = 70
self.attack = 2.5
self.name = "Warrior"
self.currenthp = 55 # arbitrary number but you may want to have something like this
def heal(warrior):
warrior.currenthp += 5
# somewhere in your Main function
warrior1 = Warrior()
heal(warrior1) # currenthp of this warrior should be 60!
It's important that you implement OOP correctly when you are creating your game. Similarly try debugging your other issues paying attention to how you implement OOP.

I'm getting this error --> TypeError: string indices must be integers

I'm trying to learn object oriented programming by making a text based rpg which is shown below. The parts of it that are related to my question are:
def equipArmor(self):
for armor in self.armorsOwned:
select = 1
if self.armor == armor:
print(str(select) + ". " + str(armor["Name"]) + " (Equipped)")
else:
print(str(select) + ". " + str(armor["Name"]))
select += 1
armor_choice = input("Type the name of the armor you would like to equip\n")
for i in self.armorsOwned:
if armor_choice == i["Name"]:
if self.armor == i:
print("You already have that equipped")
else:
self.armor = i["Name"]
print("You equipped the {}".format(i["Name"]))
self.maxhp += i["Effect"]
and:
class Shop:
armors = {"BronzeArmor":{"Name": "Bronze armor",
"Cost": 30,
"Effect": 10},
"SilverArmor":{"Name": "Silver armor",
"Cost": 75,
"Effect": 20}}
Here is the rest just so you can understand the context of my code:
import time
import sys
class Player:
def __init__(self):
self.level = 1
self.exp = 0
self.gold = 0
self.maxhp = 20
self.hp = self.maxhp
self.attack = 1
self.weapon = ""
self.armor = ""
self.weaponsOwned = {}
self.armorsOwned = {}
def checkHp(self):
self.hp = max(0, min(self.hp, self.maxhp))
def deadCheck(self):
if self.hp == 0:
print("You died!")
sys.exit()
def equipArmor(self):
for armor in self.armorsOwned:
select = 1
if self.armor == armor:
print(str(select) + ". " + str(armor["Name"]) + " (Equipped)")
else:
print(str(select) + ". " + str(armor["Name"]))
select += 1
armor_choice = input("Type the name of the armor you would like to equip\n")
for i in self.armorsOwned:
if armor_choice == i["Name"]:
if self.armor == i:
print("You already have that equipped")
else:
self.armor = i["Name"]
print("You equipped the {}".format(i["Name"]))
self.maxhp += i["Effect"]
class Enemy:
def __init__(self, attack, maxhp, exp, gold):
self.exp = exp
self.gold = gold
self.maxhp = maxhp
self.hp = maxhp
self.attack = attack
def checkHp(self):
self.hp = max(0, min(self.hp, self.maxhp))
def enemyDeadCheck(self):
if self.hp == 0:
return True
class Shop:
armors = {"BronzeArmor":{"Name": "Bronze armor",
"Cost": 30,
"Effect": 10},
"SilverArmor":{"Name": "Silver armor",
"Cost": 75,
"Effect": 20}}
character = Player()
character.armorsOwned.update(Shop.armors["BronzeArmor"])
character.equipArmor()
What I'm trying to do is print out all of the armors I have, print "equipped" beside it if it's equipped, receive the name of the armor to equip from input, check if it is already equipped and then equip it if it isn't equipped. However, the error mentioned in the title is preventing me from doing that. Why is that so and what is a string indice?
Loops over dictionaries (for example, for i in self.armorsOwned) return an iterable of the keys, not the entries. So i is being set to the key string, not the armor dictionary.
You want to turn all your loops over dictionaries to something like:
for i in self.armorsOwned.values():
Dont have enough points to make comment hence posting as answer.
This error is generally thrown when you treat a list like a dictionary.
It'd be helpful if you could include the #line that shows the error so that I could pin-point but to me this looks fishy:
self.armorsOwned = {}
If it's just a dictionary of armor. In that case, this is how you would extract the armor-name:
if self.armor == armor:
print(str(select) + ". " + str(self.armorsOwned[armor]["Name"]) + " (Equipped)")
else:
print(str(select) + ". " + str(self.armorsOwned[armor]["Name"]))
You could also try printing the values of these variables to see what they contain before doing any string manipulation:
def equipArmor(self):
print(self.armorsOwned)
for armor in self.armorsOwned:
print(armor)
select = 1
TypeError: string indices must be integers is a very common error in Python, especially during development. It indicates that your variable is a string, but you are trying to use it as a dictionary.
example:
x = {'Name': 'Bronze Armor'}
print(x['Name']) # Bronze Armor
x = 'Bronze Armor'
print(x['Name']) # raises TypeError: string indices must be integers
Look at error's stack trace, it will tell you in which line you made the mistake.

Cannot find error: calling items from libraries

I am having an issue with calling variables to add while within a definition which is in the class 'mountain'. It runs the error:
AttributeError: 'function' object has no attribute 'picture'
Here is the code for it:
import random
class currencies:
film = 5
class pictures:
picture = {"m_goat": 0, "b_eagle": 0, "marmot": 0, "r_snake": 0, "m_lion": 0, "b_dragon": 0, "vulture": 0}
class location:
city = True
shop = False
mountains = False
desert = False
class mountain:
#Travel to mountains
def travel_m():
print("You climb to the top of a tall mountain")
location.mountains = True
animals = ["mountain goat", "bald eagle", "marmot", "rattlesnake", "mountain lion"]
animal_pics = ["m_goat", "b_eagle", "marmot", "r_snake", "m_lion"]
if 1 == 1: #for simplicity I changed this to a non random number
animal = random.randint(0, 4)
str_animal = animals[animal]
ans = input("You see a wild " + str_animal + ". Would you like to take a photo? (y/n) \n")
if ans == "y" and currencies.film == 0:
print("You cannot take a picture of this animal because you are out of film")
elif ans == "y":
currencies.film -= 1
pictures.picture[animal_pics] = pictures.picture[animal_pics] + 1 #this is the line with the error
print("You took a picture of the animal")
elif ans == "n":
print("The animal was left unbothered")
else:
print("I do not recognize that command")
def pictures():
print("You have " + str(pictures.pictures['m_goat']) + " picture(s) of mountain goats")
print("You have " + str(pictures.pictures['b_eagle']) + " picture(s) of bald eagles")
print("You have " + str(pictures.pictures['marmot']) + " picture(s) of marmots")
print("You have " + str(pictures.pictures['r_snake']) + " picture(s) of rattlesnakes")
print("You have " + str(pictures.pictures['m_lion']) + " picture(s) of mountain lions")
mountain.travel_m()
Thank you for any help at all. I'm just learning the language but neither me nor my teacher could find an answer for it online. If it's something stupid, please do say
When you do:
def pictures():
you're redefining the variable pictures. It now names the function, not the class that was defined earlier.
Give the function a name that doesn't conflict with the class, e.g.
def show_pictures():
Also, in the last function you use pictures.pictures. That should be pictures.picture.
After you fix those, this line is wrong:
pictures.picture[animal_pics] = pictures.picture[animal_pics] + 1
animal_pics is a list, you can't use it as a dictionary key. I think you meant:
pictures.picture[str_animal] += 1

Python Formatting Output

I have the following code:
import options
import random
class Player():
def __init__(self):
self.name = None
self.gold = 100
self.maxhealth = 100
self.health = self.maxhealth
self.level = 1
self.exp = 0
self.levelUp = 50
self.gainedexp = self.levelUp - self.exp
def get_name(self):
self.name = input("Hey there, traveller! What's your name?\n~~>")
print("Since you are new around here, 100 gold doubloons have been given to you, {}!".format(self.name))
def gold_counter(self):
print("You currently have {} gold!".format(player.gold))
class Dragon():
def __init__(self):
self.name = "Dragon"
self.dropgold = random.randint(13,20)
self.minexp = int(15 * round(player.level * 1.5))
self.maxexp = int(30 * round(player.level * 1.5))
self.expgain = random.randint({}, {}.format(self.minexp, self.maxexp))
self.maxhealth = 80
self.health = self.maxhealth
def intro():
wrong_input = 0
nar_name = "Narrator"
print("{}: Uhhhm...".format(nar_name))
print("{}: Let me check my list...".format(nar_name))
print("{0}: Ah! Yes! {1}, that's right. I heard you were supposed to be arriving today.".format(nar_name, player.name))
I am also using two other modules, but I'm 99% sure they don't affect this. I get the following output:
Hey there, traveller! What's your name?
~~>Savage Potato
Since you are new around here, 100 gold doubloons have been given to you, Savage Potato!
Do you want to see your balance?
~~> Yes
You currently have 100 gold.
Narrator: Uhhhm...
Narrator: Let me check my list...
Narrator: Ah! Yes! None, that's right. I heard you were supposed to be arriving today.
In the last line, it is printing out the Narrator's name, but not the user's inputted name. I also looked at the python documents on their website, but I couldn't find a fix. Any ideas on how I could stop it from outputting None as the user's name?
EDIT #1: I have player = Player() written later in the module.
EDIT #2: This is all the code I used:
Module 1 (main.py)
import prints
import random
class Player():
def __init__(self):
self.name = None
self.gold = 100
self.maxhealth = 100
self.health = self.maxhealth
self.level = 1
self.exp = 0
self.levelUp = 50
self.gainedexp = self.levelUp - self.exp
def get_name(self):
self.name = input("Hey there, traveller! What's your name?\n~~>")
print("Since you are new around here, 100 gold doubloons have been given to you, {}!".format(self.name))
class Dragon():
def __init__(self):
self.name = "Dragon"
self.dropgold = random.randint(13,20)
self.minexp = int(15 * round(player.level * 1.5))
self.maxexp = int(30 * round(player.level * 1.5))
self.expgain = random.randint({}, {}.format(self.minexp, self.maxexp))
self.maxhealth = 80
self.health = self.maxhealth
#while player.exp >= player.levelUp:
#player.levelUp += 1
#player.exp = player.exp - player.levelUp
#player.levelUp = round(player.levelUp * 1.5)
#print("Congrats! You just levelled up to level {} by gaining {} experience!".format(player.level, player.gainedexp))
def start():
player.get_name()
prints.gold_counter()
prints.intro()
prints.encounter()
player = Player()
start()
Module 2 (prints.py)
import options
import random
class Player():
def __init__(self):
self.name = None
self.gold = 100
self.maxhealth = 100
self.health = self.maxhealth
self.level = 1
self.exp = 0
self.levelUp = 50
self.gainedexp = self.levelUp - self.exp
def get_name(self):
self.name = input("Hey there, traveller! What's your name?\n~~>")
print("Since you are new around here, 100 gold doubloons have been given to you, {}!".format(self.name))
def gold_counter(self):
print("You currently have {} gold!".format(player.gold))
class Dragon():
def __init__(self):
self.name = "Dragon"
self.dropgold = random.randint(13,20)
self.minexp = int(15 * round(player.level * 1.5))
self.maxexp = int(30 * round(player.level * 1.5))
self.expgain = random.randint({}, {}.format(self.minexp, self.maxexp))
self.maxhealth = 80
self.health = self.maxhealth
def intro():
wrong_input = 0
nar_name = "Narrator"
print("{}: Uhhhm...".format(nar_name))
print("{}: Let me check my list...".format(nar_name))
print("{0}: Ah! Yes! {1}, that's right. I heard you were supposed to be arriving today.".format(nar_name, player.name))
print("{}: Welcome to... THE DRAGON FIGHTER GAME!".format(nar_name))
print("{}: I know, it isn't the most imaginative name.".format(nar_name))
print("{}: Don't look at me like that, I tried my hardest!".format(nar_name))
print("{}: Anyhoo, let's carry on.".format(nar_name))
print("{}: For some stupid reason, the creator of this game didn't give me an actual name, so\nmy name is just \"Narrator\" or \"N\", but you can call me Larry.".format(nar_name))
while True:
option = input("Narrator: Actually, which name would you prefer to call me?\n").upper()
if option in options.nar_larry_opt:
nar_name = "Larry"
elif option in options.nar_narrator_opt:
nar_name = "Narrator"
while True:
ask = input("{}: Maybe \"N\" for short?".format(nar_name)).upper()
if ask in options.inp_yes_opt:
nar_name = "N"
elif ask in options.inp_no_opt:
break
else:
wrong_input += 1
if wrong_input == 1:
print("Please try again.")
elif wrong_input == 2:
print("Try to not put the same thing in next time.")
elif wrong_input == 3:
print("This isn't funny.")
elif wrong_input == 4:
print("Seriously.")
elif wrong_input == 5:
print("OKAY! THIS IS IT! GO BACK TO THE BEGINNING!")
intro()
continue
break
else:
print("Please try again.")
continue
break
print("{}: So, as I was saying, this game is basically just some dragon quest thingy.".format(nar_name))
print("{}: You'll probably get tips from me every now and again if I can be bothered.".format(nar_name))
print("{}: I'll get an test encounter ready.".format(nar_name))
def gold_counter():
while True:
option = input("Do you want to see your balance?\n~~> ").upper()
if option in options.inp_yes_opt:
print("You currently have {} gold.".format(player.gold))
elif option in options.inp_no_opt:
print("You can check your balance later in the game.")
else:
print("Please try again.")
continue
break
def encounter():
while True:
dragon_appear = random.randint(1,2)
if dragon_appear == 1:
print("What's that? Looks like a huge bir... \nA DRAGON! A MAJESTIC DRAGON JUST FLEW DOWN FROM THE SKY!")
else:
print("What's that? Looks like a huge bir... \n Yeah. Just a giganta-bird.")
while encounter().dragon_appear != 2:
print("So that's the message you'll get when a dragon appears.")
print("And you will be prompted whether you want to run or fight, like so:")
while True:
wrong_input = 0
ask = input("Run away like a coward, or fight the majestic beast?")
if ask in options.enc_run_opt:
escape = random.randint(1,2)
if escape == 1:
print("You managed to get away!")
else:
print("You didn't get away. Better luck next time!")
elif ask in options.enc_attack_opt:
pass
else:
wrong_input += 1
if wrong_input == 1:
print("Please try again.")
elif wrong_input == 2:
print("Try to not put the same thing in next time.")
elif wrong_input == 3:
print("This isn't funny.")
elif wrong_input == 4:
print("Seriously.")
continue
break
player = Player()
Module 3 (options.py)
inp_yes_opt = {"Y", "YE", "YES", "YEAH", "PLEASE", "YES PLEASE"}
inp_no_opt = {"N", "NO", "NOPE", "NAH"}
nar_larry_opt = {"LARRY", "LARR", "LAR", "LA", "L", "LARRY PLEASE"}
nar_narrator_opt = {"NARRATOR", "NARR", "N", "NAR", "NARRATE", "NOT LARRY"}
enc_run_opt = {"RUN", "RU", "R", "SCRAM", "RUN AWAY", "RUUUUN"}
enc_attack_opt = {"ATTACK", "ATTAK", "A", "FIGHT", "F", "ATTACK", ""}
If you want to print out the name of the player , you need to pass in the player object to the intro function as a parameter. That assumes intro is not capturing the player object and the player object is not global
At the moment , it seems there is no player object accessible to the scope of the function which is why it outputs None

Categories

Resources