modul:archiv:m319python:learningunits:lu09:loesungen:einfachefunktionen

LU09.L01 - Einfache Funktionenen

def function1():
    """
    Function without params or return
    :return: None
    """
    print('Function 1 is called')
 
 
def function2():
    """
    Function with return
    :return: returns a number
    """
    return 69
 
 
def function3(name):
    """
    Welcomes the user with "name"
    :param name (str): Name of user to welcome
    :return: None
    """
    print(f'Welcome {name}')
    #print('Welcome ' + name)
 
 
def function4(number_to_sqaure):
    """
    Squares a number
    :param number_to_square (int): number to sqaure
    :return (int): Number
    """
    result = number_to_sqaure * number_to_sqaure
    return result
 
 
def four_functions():
    """
    Main function
    :return: None
    """
    function1()
    received_from_2 = function2()
    print(received_from_2)
    function3('Peter')
    received_from_4 = function4(12)
    print(received_from_4)
 
if __name__ == '__main__':
    four_functions()
import math
 
 
def add(num1, num2):
    """
    Addition of two numbers
    :param num1: number 1 for calculation
    :param num2: number 2 for calculation
    :return: result of calculation
    """
    return num1 + num2
 
 
def sub(num1, num2):
    """
    Substracts two numbers
    :param num1: number 1 for calculation
    :param num2: number 2 for calculation
    :return: result of calculation
    """
    return num1 - num2
 
 
def mul(num1, num2):
    """
    multiply of two numbers
    :param num1: number 1 for calculation
    :param num2: number 2 for calculation
    :return: result of calculation
    """
    return num1 * num2
 
 
def div(num1, num2):
    """
    division of two numbers
    :param num1: number 1 for calculation
    :param num2: number 2 for calculation
    :return: result of calculation
    """
    return num1 / num2
 
 
def pow(num1):
    """
    Squares two numbers
    :param num1: number to square
    :return: result of calculation
    """
    return num1 * num1
 
 
def sqrt(num1):
    """
    return the root of a number
    :param num1: number to get the root of
    :return: result of calculation
    """
    return math.sqrt(num1)
 
 
def main():
    result_add = add(5, 5.5)
    result_div = div(10, 3)
    result_mul = mul(3, 3)
    result_sub = sub(10, 4.4)
    result_pow = pow(23)
    result_sqrt = sqrt(81)
 
    print(result_add)
    print(result_div)
    print(result_mul)
    print(result_sub)
    print(result_pow)
    print(result_sqrt)
 
 
if __name__ == '__main__':
    main()
  • modul/archiv/m319python/learningunits/lu09/loesungen/einfachefunktionen.txt
  • Zuletzt geändert: 2024/03/28 14:07
  • von 127.0.0.1