Python

To Bottom

# Python

# Declarations / Importations

To Top

# Input

To Top

# Output

To Top

# Arrays

To Top

# Maps / Dictionaries


    super_villians = {"Big Foot": "Veto von Vaughn", "Lex Luth": "Mack Moroue",
        "Darth Dot": "Jack Cracker", "Mr. Monster": "Dick", "Anthrax Jack": "Colen",
        "Count Chocula": "King Vampire", "Georgey Porgy": "Bush"}
    print(super_villians)
    print(super_villians["Darth Dot"])
    del (super_villians["Lex Luth"])
    super_villians["Big Foot"] = "Chewey"
    print(len(super_villians))
    print(super_villians.get("Big Foot"))
    print(super_villians.keys())
    print(super_villians.values())
    

To Top

# Tuples

To Top

# Conditionals - if, else, elif, and, or, not


    age = 20
    if age >= 15 :
        print("You can drive")
        if age >= 21 :
            print("You can drive a tractor-trailer")
        elif age == 15 :
            print("You may use a lerner's permit")
        else : print("You can drive a car")
    else :
        print("You cannot drive")
    if ((age >= 9) and (age <= 18)):
        print("You must sign up for the Hunger Games")
    elif ((age == 44) or (age >= 65)):
          print("Go to the hog farm")
    #elif not(age == 21):
    elif age !=21 :
        print("You are not 21")
    

To Top

# Loops


    for x in range(0,10):
        print(x, ' ', end="")
    print("")
    for y in grocery_list:
        print(y)
    for x in [2,4,8,16,32,64]:
        print(x, end="")
    num_list = [[1,2,3],[10,20,30,],[100,200,300]]
    for x in range(0,3):
        for y in range(0,3):
            print(num_list[x][y], end="")
        
    i = 1;
    while(i <= 20):
        if(i%2 == 0):
            print(i)
        elif(i == 9):
            break
        else:
            i += 1
            continue
        i += 1
    

To Top

# Random numbers


    random_num = random.randrange(0,100)
    while(random_num != 15):
        print(random_num, end="")
        random_num = random.randrange(0,100)
    

To Top

# Functions


    def add_numbers(numA, numB):
        sumNum = numA + numB
        return sumNum
    print(add_numbers(2, 4))
    

To Top

# File I/O

To Top

# Classes

    
    class Animal:
        __name = ""
        __height = 0
        __weight = 0
        __sound = ""
        def __init__(self, name, height, weight, sound):
            self.name = name
            self.height = height
            self.weight = weight
            self.sound = sound
        def set_name(self, name):
            self.__name = name          
        def get_name(self):
            return self.__name
    
        def set_height(self, height):
            self.__height = height
        def get_height(self):
            return self.__height
        def set_weight(self, weight):
            self.__weight = weight
        def get_weight(self):
            return self.__weight
    
        def set_sound(self, sound):
            self.__sound = sound
        def get_sound(self):
            return self.__sound
        def get_type(self):
            print("Animal")
        def toString(self):
            return "{} is {} cm tall and {} kilos and says {}".format(self.__name, self.__height, self.__weight, self.__sound)
    cat = Animal("Diamond", 33, 10, "meow")
    print(cat.toString())
    

To Top