def find_min(L):
n = len(L)
current_min = L[0]
i = 1
while i < n:
if L[i]<current_min:
current_min = L[i]
i = i + 1
return current_min
L = [15, 3, 17, 22, 9 , 8]
find_min(L)
print("Hello")
x = 17
print(f"Hello, the variable x is equal to {x}")
print("Hello")
print("World")
print(7, "Banana", x*5)
def find_min(L):
n = len(L)
print(f"Length of L is {n}")
current_min = L[0]
print(f"current_min is {current_min}")
i = 1
print("Entering loop")
while i < n:
print(f" Loop with i={i}, L[i]={L[i]}")
if L[i]<current_min:
print(f" Updating current_min to {L[i]}")
current_min = L[i]
i = i + 1
print(f"Value of i is {i}")
print(f"Final output is {current_min}.")
return current_min
L = [15, 3, 17, 22, 9 , 8]
find_min(L)
Notebook composed of cells. Every cell either has text (markdown) or code. If you press Shift+ENTER on a code cell then you run it. The value of the last line is then printed.
# What will be printed
i = 5
i = i + 1
i*2
Use Kernel
-> Restart & Clear Output
to erase all variables and start from the beginning
print("hello") # print("World") This is a comment in the middle of code. It will not run
x = 5 # integer
y = 6.5 # floating point (number with fraction)
z = "Boaz" # string
w = False
type(x),type(y),type(z),type(w)
type('Hello world!')
print('Hello world!')
x = 'Hello world!'
print(f"x is a variable of type {type(x)}, the value of x is {x}")
type( 5 / 2)
type([0, 1, 2])
type(5>3)
# Here is an example of a NoneType
type(None)
x = 1
# Putting a variable at the end of a code block will print it
x
# You can find the type of what the variable holds by using type
type(x)
# Variables can be reassigned
x = 2
x
# The name of a variable is not related to the content at all
two = 4
two
# Variables are case-sensitive
X = 4.
print(X,x)
# Variables are case-senstive for any part of the variable
Xyz = 3
XYz