Skip to content

Example Functions

my_adder

function to sum the 3 numbers Input: 3 numbers a, b, c Output: the sum of a, b, and c author: date:

Source code in example_functions.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
def my_adder(a, b, c):
    """
    function to sum the 3 numbers
    Input: 3 numbers a, b, c
    Output: the sum of a, b, and c
    author:
    date:
    """

    # this is the summation
    out = a + b + c
    return out

my_thermo_stat

Changes the status of the thermostat based on temperature and desired temperature author date :type temp: Int :type desiredTemp: Int :rtype: String

Source code in example_functions.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def my_thermo_stat(temp, desired_temp):
    """
    Changes the status of the thermostat based on 
    temperature and desired temperature
    author
    date
    :type temp: Int
    :type desiredTemp: Int
    :rtype: String
    """
    if temp < desired_temp - 5:
        status = 'Heat'
    elif temp > desired_temp + 5:
        status = 'AC'
    else:
        status = 'off'
    return status

have_digits

Checks if a string has digits in it

Source code in example_functions.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def have_digits(s):
    """
    Checks if a string has digits in it
    """

    out = 0

    # loop through the string
    for c in s:
        # check if the character is a digit
        if c.isdigit():
            out = 1
            break

    return out