-
Notifications
You must be signed in to change notification settings - Fork 0
Description
This part of the project documentation focuses on a
problem-oriented approach. You'll tackle common
tasks that you might have, with the help of the code
provided in this project.
How To Add Three Numbers (my_adder)?
You have three numbers and you need to add them together.
You're in luck!
Download the code below:
::: functions.my_adder
Inside of my_adder.py
you can define a python function
my_adder()
that takes three parameters 'a', 'b', and 'c'.
You can assign values to find the sum of the three numbers. And the result is stored in the variable "out".
You are now able to add three numbers.
How To Change the status of the thermostat?
This python function ("my_thermo_stat") takes two parameters: 'temp' (current temperature) and 'desired_temp' (desired temperature).
It determines the status of a thermostat based on the two parameters.
Download the code below:
::: functions.my_thermo_stat
Inside of my_thermo_stat.py
you can define a python function
my_thermo_stat()
that takes two parameters 'a', 'b', and 'c'.
The function uses conditional statements (if, elif, else) to determine the thermostat status based on the temperature difference between the current temperature (temp) and the desired temperature (desired_temp).
If the current temperature is more than 5 degrees below the desired temperature, it sets the status to "Heat".
If the current temperature is more than 5 degrees above the desired temperature, it sets the status to "AC".
If the temperature difference is within 5 degrees, it sets the status to "off".
You are now able to determine the status of thermostat.
How To Check If a String has a Digit?
This python function ("have_digits") takes a single parameter ('s') that is expected to be a string.
You can download the code below:
::: functions.have_digits
The 'have_digits' function checks if a given string contains any digits.
A for loop is used to iterate through each character in the input string.
The isdigit() method is used to check if a character is a digit.
The variable out is used to indicate whether digits were found (1) or not (0) in the string.
The function returns 1 if digits were found and 0 if not.
This code provides a simple utility to determine if a string contains any digits. If it does, the function returns 1; otherwise, it returns 0.
How To Calculate The Area Of a Rectangle?
This function 'area_of_rectangle' calculates the area of rectangle based on the provided width and height.
You can download the code below:
::: functions.area_of_rectangle
The 'area_of_rectangle' function calculates the area of a rectangle using the provided 'width' and 'height'.
The variables width and height are set to specific values within the functions. You may define your own reasonable values of the width and height.
How To Calculate Perimeter Of a Rectangle?
This function 'perimeter_of_rectangle' calculates the perimeter of rectangle based on the provided width and height.
You can download the code below:
::: functions.perimeter_of_rectangle
The 'perimeter_of_rectangle' function calculates the perimeter of a rectangle using the provided 'width' and 'height'.
The variables width and height are set to specific values within the functions. You may define your own reasonable values of the width and height.