<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Throughout this tutorial, feel free to change the code and play around with it to see what will break it.
Data Types & Expressions
Step1:  A function is a way of calling the same sequence, without having to rewrite it.
A comment begins with '#' in Python and a docstring is delimited by 3 single quotes as seen below. Comments and docstrings explain the code.
Step2:  A variable is a storage location. It represents a value. Below, the variable 'x' is assigned to the integer value 4.
Step3:  Below are examples of the basic math operations in Python. The ones you might not be used to are integer division (which uses //) which returns the closest integer value when the number is divided. Modulus (uses %) returns the remainder.
Step4:  Python provides a lot of pre-written code, called "modules" which can be imported so we don't have to reinvent the wheel. For example, the below pow function works much faster than the above implementation (only noticable for larger values).
Step5:  We can convert the above cell into a function. The value that we pass in (called a "parameter") to exponent can be easily changed. Feel free to change the values of x and n and see how the output changes accordingly.
Step6:  If a function returns a value, you can assign the output of the function to a variable.
Step7:  Another useful module is random. Below we generate a random integer between the two parameters to randint. You will notice that if you run the below cell multiple times, the output will be different since it is generated randomly.
Step8:  A string is a sequence of characters. This is the type of 'Hello, world!' which we printed earlier. Strings can be concatenated and spliced. You can use the len function to find the length.
Step9:  Types are string, integer, float (decimal), etc. Types often are not compatible. What happens if you run the following?
Step10:  In Python, you can easily see what type each variable is as follows
Step11:  How to fix that problem
Step12:  You can access parts of a string with an index value. In computer science, index values begin with 0.
Step13:  You can access elements from the back of the string as follows
Step14:  Get substrings by using colons.
Step15:  An array or list is a list of elements accessible by index values, similar to strings. They also have some built in features like the sum function shown below.
Step16:  Conditional statements execute only if the condition is true. Booleans are types which evaluate to True or False in Python.
Step17:  Multiple conditions can be handled with elif.
Step18:  and and or are two basic logical constructs in computer science.
Step19:  Practice Exercises
Step20:  Loops
A while loop executes until the condition is no longer true or the function "breaks".
The below loop ends when x is no longer less than 5.
Step21:  The below loop ends when it hits the break when the value of y is 7.
Step22:  A for loop executes for the number of times indicated.
<ASSISTANT_TASK:>
Python Code:
# Prints Hello, world!
print('Hello, world!')
Explanation: Throughout this tutorial, feel free to change the code and play around with it to see what will break it.
Data Types & Expressions
End of explanation
def hello():
    '''Function that prints Hello, world!
    '''
    print('Hello, world!')
hello()
Explanation: A function is a way of calling the same sequence, without having to rewrite it.
A comment begins with '#' in Python and a docstring is delimited by 3 single quotes as seen below. Comments and docstrings explain the code.
End of explanation
x = 4
print(x)
Explanation: A variable is a storage location. It represents a value. Below, the variable 'x' is assigned to the integer value 4.
End of explanation
# Addition
print(x+5)
# Subtraction
print(x-5)
# Multiplication
print(x*5)
# Division
print(x/5)
print(x//5) #integer
# Modulus (remainder)
print(x%5)
print(x%2)
# Exponent
print(x**2)
Explanation: Below are examples of the basic math operations in Python. The ones you might not be used to are integer division (which uses //) which returns the closest integer value when the number is divided. Modulus (uses %) returns the remainder.
End of explanation
# Importing the module
import math 
y = math.pow(x, 2)
print(y)
Explanation: Python provides a lot of pre-written code, called "modules" which can be imported so we don't have to reinvent the wheel. For example, the below pow function works much faster than the above implementation (only noticable for larger values).
End of explanation
def exponent(n):
    x = 3
    # You can change the value of x here if you want, or make it a parameter of the function.
    return math.pow(x,n)
exponent(3)
Explanation: We can convert the above cell into a function. The value that we pass in (called a "parameter") to exponent can be easily changed. Feel free to change the values of x and n and see how the output changes accordingly.
End of explanation
result = exponent(4)
print(result)
print(result + 3)
Explanation: If a function returns a value, you can assign the output of the function to a variable.
End of explanation
import random
# Generating random integer between 5 and 10.
z = random.randint(5,10)
print(z)
Explanation: Another useful module is random. Below we generate a random integer between the two parameters to randint. You will notice that if you run the below cell multiple times, the output will be different since it is generated randomly.
End of explanation
name = 'shreya'
print(name)
# Print the length of name.
print(len(name))
# Concatenation example
print(name + 'test')
Explanation: A string is a sequence of characters. This is the type of 'Hello, world!' which we printed earlier. Strings can be concatenated and spliced. You can use the len function to find the length.
End of explanation
print(name+x)
Explanation: Types are string, integer, float (decimal), etc. Types often are not compatible. What happens if you run the following?
End of explanation
print(type(name))
print(type(x))
Explanation: In Python, you can easily see what type each variable is as follows:
End of explanation
print(name + str(x)) 
Explanation: How to fix that problem: Convert x to a string type.
End of explanation
name[0]
Explanation: You can access parts of a string with an index value. In computer science, index values begin with 0.
End of explanation
name[-1]
Explanation: You can access elements from the back of the string as follows:
End of explanation
name[0:2]
Explanation: Get substrings by using colons.
End of explanation
example_list = [1, 2, 3, 4]
print(example_list[0])
print(example_list[-1])
print(example_list[0:2])
print(sum(example_list))
Explanation: An array or list is a list of elements accessible by index values, similar to strings. They also have some built in features like the sum function shown below.
End of explanation
x = 5
# Prints whether x is greater or less than 10.
if x > 10:
    print('Greater than 10')
else:
    print('Less than 10')
# Prints type of condition.
print(type(x>10))
# Prints value of condition.
print(x>10)
Explanation: Conditional statements execute only if the condition is true. Booleans are types which evaluate to True or False in Python.
End of explanation
if x > 5:
    print('Greater than 5')
elif x < 5:
    print('Less than 5')
else:
    print('Equal to 5')
Explanation: Multiple conditions can be handled with elif.
End of explanation
y = 10
if y > 2 and x > 2:
    print('y greater than 2 AND x greater than 2')
if y > 5 and x > 5:
    print('y greater than 2 AND x greater than 5')
if y > 5 or x > 5:
    print('y greater than 2 OR x greater than 5')
Explanation: and and or are two basic logical constructs in computer science.
End of explanation
def goodbye():
    pass
    #Implement this function so that it operates similarly to the hello function in the first cell
# Implement a conditional statement such that if the value of x is greater than 5, 'Hello, world' is printed
# If not, print 'Goodbye, world'
# Calculate average of example_list
Explanation: Practice Exercises
End of explanation
x = 0
while x < 5:
    print('Executing while loop')
    x +=1
Explanation: Loops
A while loop executes until the condition is no longer true or the function "breaks".
The below loop ends when x is no longer less than 5.
End of explanation
y = 5
while y < 10:
    print('Executing while loop')
    y+=1
    if y==7:
        print('y=7')
        break
Explanation: The below loop ends when it hits the break when the value of y is 7.
End of explanation
n = 5
for i in range(0,n):
    print('Executing for loop, iteration #'+str(i))
Explanation: A for loop executes for the number of times indicated.
End of explanation
<END_TASK>