In [13]:
# Practice Problem 1
# Write a function that returns the maximum of two numbers.
#
def max2(num1,num2):   # function header or function signature; contains NAME of function and a list of parameter NAMES    
    if num1 > num2:
        return num1
    else:
        return num2

# What is a parameter?
# it is a generic name to variable that is typically an INPUT to a function 
In [14]:
print(max2(10,20))
print(max2(30,5))
40
35
In [15]:
max2(100,200)
Out[15]:
220
In [25]:
def nationality(name):
    ???
    ???


def uselessFunction(name):
    if nationality(name) == "India":
        return "Namaste"
    else:
        return "Hello"
In [26]:
uselessFunction("")
Out[26]:
'Hello'
In [28]:
uselessFunction("James")
Out[28]:
'Namaste'
In [22]:
for i in range(10):
    print(uselessFunction())
Namaste
Namaste
Namaste
Namaste
Namaste
Namaste
Namaste
Namaste
Namaste
Namaste
In [23]:
print("Namaste")
Namaste
In [29]:
def square(n):
    return n*n
In [37]:
square(10000000000000000000000000000) == 100000000000000000000000000000000000000000000000000000000
Out[37]:
True
In [ ]:
# FINITE DIGITAL COMPUTER
# ANALOG COMPUTER
# INIFINITE PRECISION ARITHMETIC
In [41]:
# Problem 2
# Write a function called fizz_buzz that takes a number as parameter. 
# If the number is divisible by 3, it should return “Fizz”. C1 
# If it is divisible by 5, it should return “Buzz”. C2
# If it is divisible by both 3 and 5, it should return “FizzBuzz”. C3
# Otherwise, it should return the same number.

# C3 implies C1 and C2
def fizz_buzz(num):
    if num%3 == 0 and num%5 == 0:
        return "FizzBuzz"
    elif num%3 == 0:
        return "Fizz"
    elif num%5 == 0:
        return "Buzz"
    else:
        return str(num)
In [45]:
fizz_buzz(8)
Out[45]:
'8'
In [39]:
9%3
Out[39]:
0
In [48]:
13//3
13%3
Out[48]:
1
In [ ]:
+, -, *, /, %, //,