• Предмет: Информатика
  • Автор: termienoy
  • Вопрос задан 5 месяцев назад

создать код пайтон симулятор человака наподобие если ти даш кушать то шястя +10 только не огромний код без табуляций
СРОЧНО ПОМОГИТЕ ДАЮ 90 БАЛОВ

Ответы

Ответ дал: anonymous2010
1

import random

class Disease():

   def __init__(self, name="OldAge") -> None:

       self.name = name

   def damage(self, life) -> dict:

       return {

           'heal' : -1*(life//10),

           'happiness' : -2*(life//10),

           'hunger' : -3

       }

   def __str__(self) -> None:

       return self.name

class Human():

   food = {

       'apple' : {

           'happiness' : 1,

           'hunger' : 2

       },

   }

   commands = ['eat', 'haveFun']

   def __init__(self, life=18, heal=100, diseases=[Disease()], hunger=50, happiness=50):

       self.life = life

       self.hunger = hunger

       self.heal = heal

       self.happiness = happiness

       self.lastFood = None

       self.diseases = diseases

       self.alife()

   def eat(self) -> None:

       j = 0

       for i in self.food.keys():

           j+=1

           print(f"{j}) {i}")

       choice = int(input('You choice: ')) - 1

       if -1 > choice > len(self.food.keys()):

           return

       choiceFood = self.food[[i for i in self.food.keys()][choice]]

       addHappiness = choiceFood['happiness'] if choiceFood != self.lastFood else -choiceFood['happiness']

       addHunger = choiceFood['hunger']

       if self.hunger > 100:

           if addHappiness < 0:

               addHappiness = -addHappiness * 10

           self.happiness -= addHappiness

           self.heal -= 1

       else:

           self.happiness += addHappiness

           self.hunger += addHunger

       self.lastFood = choiceFood

   def haveFun(self) -> None:

       self.happiness += random.randint(1,6)

       if self.happiness > 150:

           self.heal = 0

   def __str__(self):

       return ''+\

           f"life = {self.life}\n"+\

           f"heal = {self.heal}\n"+\

           f"happiness = {self.happiness}\n"+\

           f"hunger = {self.hunger}\n"+\

           f"diseases = {', '.join([str(disease) for disease in self.diseases])}"

   def alife(self) -> None:

       while (self.heal > 0):

           print('info:\n')

           print(str(self), end="\n\n")

           j = 0

           for i in self.commands:

               j+=1

               print(f"{j}) {i}")

           

           try:

               choice = int(input("You choice: ")) - 1

               print()

               eval("self."+self.commands[choice]+"()")

           except:

               break

           if self.happiness < 50:

               self.heal -= (100 - self.happiness) // 10

           if self.hunger < 40:

               self.heal -= (100 - self.happiness) // 10

           self.life += 1

           for disease in self.diseases:

               diseaseDamage = disease.damage(self.life)

               self.heal += diseaseDamage['heal']

               self.happiness += diseaseDamage['happiness']

               self.hunger += diseaseDamage['hunger']

           print("\n"*30)

       print("You death!\nYou age:", self.life)

if __name__ == '__main__':

   Human()

Вас заинтересует