+ 2
Intermediate Python - 20.2 Practice help- âGame Overâ
You are making a video game! The given code declares a Player class, with its attributes and an intro() method. Complete the code to take the name and level from user input, create a Player object with the corresponding values and call the intro() method of that object. Sample Input Tony 12 Sample Output Tony (Level 12) Current code in 1st comment. Please help, thanks!
9 Answers
+ 4
instead of:
print(intro)
do:
user_name = input()
user_level = input()
user = Player(user_name, user_level)
user.intro()
+ 2
Complete the code to display the game over message on the screen
+ 1
Code:
class Player:
def __init__(self, name, level):
self.name = name
self.level = level
def intro(self):
print(self.name + " (Level " + self.level + ")")
print(intro)
0
print(intro) just raise error...
you must take input from user (name and level), construct a new Player instance with them, and call the intro() method on it ^^
0
Thanks visph !
0
class Player:
def __init__(self, name, level):
self.name = name
self.level = level
def intro(self):
print(self.name + " (Level " +str(self.level)+")")
name = input()
Level = "X"
try:
Level_input = input()
if not Level_input:
raise ValueError()
Level = int(Level_input)
except ValueError:
print()
Player1 = Player(name, Level)
Player1.intro()
0
class Player:
def __init__(self, name, level):
self.name = name
self.level = level
def intro(self):
print(self.name + " (Level " + str(self.level) + ")")
name = input()
level = input()
player = Player(name, level)
player.intro()
- 1
Thanks visph but im not following/sure what to do next? Appreciate the guidance.
- 1
almost: remove "print(intro)" from your code ;P