Untitled

mail@pastecode.io avatar
unknown
python
3 years ago
1.0 kB
6
Indexable
from random import randint

class NumberGuessGame:
  def __init__(self, name):
    self.name = name
    self.score = 100

  def run(self):
    number = randint(1, 100)
    guess = 0
    while guess != number:
      guess = int(input("Guess the number "))
      if number == guess:
        self.print_congratulatory_message(self.name, self.score)
      else:
        self.print_hint(number, guess)
        self.decrease_score()
  
  @staticmethod
  def print_congratulatory_message(name, score):
    print(f"Congrats! {name}, your score is {score}")

  def print_hint(self, number, guess):
    hint = ""
    if number > guess:
        hint += "Way too Low "
    elif number < guess:
        hint += "Way too High "
    if (number % 2 == 0 and guess % 2 == 1):
        hint += ", try an even number "
    if (number % 2 == 1 and guess % 2 == 0):
        hint += ", try an odd number "
    hint += self.name
    print(hint)

  def decrease_score(self):
    self.score -= 5

program = NumberGuessGame(name="Vanessa")
program.run()