+ 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!

10th Jul 2021, 7:51 PM
Zach Z
9 RĂ©ponses
+ 4
instead of: print(intro) do: user_name = input() user_level = input() user = Player(user_name, user_level) user.intro()
11th Jul 2021, 4:40 PM
visph
visph - avatar
+ 2
Complete the code to display the game over message on the screen
15th Sep 2023, 11:46 AM
Kanishka Govil
+ 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)
10th Jul 2021, 7:52 PM
Zach Z
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 ^^
10th Jul 2021, 7:55 PM
visph
visph - avatar
0
Thanks visph !
11th Jul 2021, 4:42 PM
Zach Z
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()
8th Dec 2023, 5:07 PM
Naseem Tahir
Naseem Tahir - avatar
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()
5th Mar 2024, 9:07 AM
Mohammad Soltanpour
- 1
Thanks visph but im not following/sure what to do next? Appreciate the guidance.
11th Jul 2021, 4:36 PM
Zach Z
- 1
almost: remove "print(intro)" from your code ;P
11th Jul 2021, 4:42 PM
visph
visph - avatar