Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>Kuhler CodeNew to Visual Studio Code? Get it now.
Kuhler Code

Kuhler Code

kuhlekadse

|
24 installs
| (0) | Free
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Kuhlercode

import json import os

class BodyMassIndex:

# ----------------------------------
#          Konstruktor
# ----------------------------------
def _init_(self, counter, lastname, firstname, age, height, weight):
    
    self.number = counter
    
    self.lastname = lastname
    self.firstname = firstname
    self.age = age
    self.height = height
    self.weight = weight
    
    # self.display_infos()
    # self.bmi()

# ----------------------------------
#          Infos anzeigen
# ----------------------------------
def display_infos(self):
    print(f"\n>>> {self.lastname.upper()} {self.firstname} ({self.age})") 
    print(f">>> Höhe: {self.height} m / Gewicht: {self.weight} kg")
# ----------------------------------
#          BMI berechnen
# ----------------------------------
def bmi(self):
    self.bmi_score = self.weight/(self.height ** 2)
    print(f">>> Dein BMI ist : {self.bmi_score:.2f}")
    
    # self.analysis()
# ----------------------------------
#       Kommentar zurückgeben
# ----------------------------------
def analysis(self):
    
    # Fettleibigkeit
    
    if self.bmi_score < 16.5:
        self.health_status = "Unterernährung"
    elif self.bmi_score < 18.5:
        self.health_status = "Schlankheit"
    elif self.bmi_score < 25:
        self.health_status = "Normales Gewicht"
    elif self.bmi_score < 30:
        self.health_status = "Übergewicht"
    elif self.bmi_score < 35:
        self.health_status = "Fettleibigkeit Klasse 1 (mäßig)"
    elif self.bmi_score < 40:
        self.health_status = "Fettleibigkeit Klasse 2 (schwer)"
    else:
        self.health_status = "Fettleibigkeit Klasse 3 (morbide)"
    
    print(f">>> Gesundheitszustand: {self.health_status}")
    
    # self.update_dictionary()

def update_dictionary(self):
    
    person_infos.update( {
                    self.number : {
                        
                    "Name":self.lastname,
                    "Vorname":self.firstname,
                    "Alter":self.age,
                    "Höhe": self.height,
                    "Gewicht": self.weight,
                    "BMI": self.bmi_score,
                    "Gesundheitszustand": self.health_status
                    }
        
        
    })

----------------------------------

Eingabe-Funktion

----------------------------------

def my_infos():

print("\n\tDeine Daten")
print("\t-----------") 

lastname = input  ("\n  >         Name: ")
firstname = input ("  >      Vorname: ")

while True:
    try:
        age = int(input   ("\n  >        Alter: "))
        if age <= 0:
            print("\n\t>>> Dein Alter soll größer oder gleich null sein!")
            continue      
    except:
        print("\n\t>>> Dein Alter ist ungültig. Versuch mal wieder!\n")
    else:
        break

while True:
    try:
        height = float(input("  >     Höhe (m): "))
        if height <= 0:
            print("\n\t>>> Die Höhe soll größer oder gleich null sein!")
            continue   
    except:
        print("\n\t>>> Die Höhe ist ungültig. Versuch mal wieder!\n")
    else:
        break
                
while True:
    try:     
        weight = float(input("  > Gewicht (kg): "))
        if weight <= 0:
            print("\n\t>>> Das Gewicht soll größer oder gleich null sein!")
            continue   
    except:
        print("\n\t>>> Das Gewicht ist ungültig. Versuch mal wieder!\n")
    else:
        break                    
                      
return lastname, firstname, age, height, weight
# ODER return BodyMassIndex(lastname, firstname, age, height, weight)

----------------------------------

Hauptprogramm

----------------------------------

counter = 0 person_infos = {}

print("\n\t\tBody Mass Index") print("\t\t---------------")

while True:

my_choice = input("\n> Möchtest du deinen Körpermassenindex (BMI) berechnen (J/N)? ").lower()

if my_choice == "j":
    counter += 1
    datas = my_infos()
    person = BodyMassIndex(counter, datas[0], datas[1], datas[2], datas[3], datas[4])
    
    # Aufrufe der Methoden - ODER in der Klasse
    person.display_infos()
    person.bmi()
    person.analysis()
    person.update_dictionary()

else:
    os.system("clear")
    
    for element in person_infos:
    
        print(f'{element}: {person_infos[element]["Name"]} {person_infos[element]["Vorname"]} ({person_infos[element]["Alter"]}): BMI {person_infos[element]["BMI"]:.2f} - {person_infos[element]["Gesundheitszustand"]}')
    print("\nVielen Dank. Auf Wiedersehen...\n")
    break

pfad = "/Users/michaelspiekermann/Desktop/bmi.json" with open(pfad,"w") as datei: json.dump(person_infos,datei,ensure_ascii=False)

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft