yor-discord-bot / py_files / yor_random.py
yor_random.py
Raw
import random
import collections

def magic_8ball() -> str:
    """Returns a random phrase from a pool of answers.

    Args:
        None.

    Returns:
        A str representing a phrase to an answer.
    """
    answers = ["yes", "uhuh", "maybe", "no"]
    return random.choice(answers)
    
def measure_rng(guess: int, min: int, max: int) -> str:
    """
    
    """
    responses = [
        "Not even close", 
        "Oh you kinda average", 
        "AY GOOD JOB DUD",
        ]
    rand = random.randint(min, max)
    if guess == rand:
        return responses[2]
    # return a response based on closeness score
    closeness = abs(guess - rand) / (max - min)
    if closeness < 0.4:
        return responses[1]
    else:
        return responses[0]

def take_sum() -> int:
    numbers = [1, 2, 3, 4, 5, 6]
    return sum(numbers)

# https://docs.python.org/3/tutorial/datastructures.html
# https://www.programiz.com/python-programming/dictionary
def dict_basics():
    d = dict()
    #   key : value
    d = {
        'sum0': 2,
        'sum1': 3,
        'sum2': 4,
        }
    
    # ITERATING THROUGH A DICTIONARY

    # d.items()  -> returns a collection of keys and values
    # d.keys()   -> returns a collection of keys
    # d.values() -> returns a collection of values

    # for key in d:
        # print(key)

    # if 'sum1' in d:
    #     print('true')

    # d['sum1'] = 2
    print('original:', d)
    # d.clear()
    # print('cleared: ', d)

    # len(d) is equivalent to d.length
    # len is __len__
    print(len(d))

    popped = d.pop('sum0')
    print('popped:  ', popped)

    d['sum0'] = 8
    print(d)


def list_basics():
    l = list()
    l.append('sum0')
    l.append('sum1')
    l.append('sum2')

    print('original:', l)
    l.reverse()
    print('reversed:', l)
    l.sort()
    print('sorted:  ', l)

def main():
    # magic_8ball()
    # print(measure_rng(69, 68, 70))
    # dict_basics()    
    # list_basics()
    print(take_sum())

if __name__ == '__main__':
    main()