'''
Program: 1
Description: Calling the addition function multiple times within the same function.
The function add just takes two inputs from the user, adds them and returns it.
Author: Tanu Nanda Prabhu
'''
def add(a, b): # Function declaration to add to numbers
c = a + b # Adds two number and stores them in variable c
return c # Returns the result
# Calling the function by passing the input parameters.
result = add(add(add(5, add(5, 6.5)), 5), 5)
print("---------------------------------------------")
print("The final result is:", result)
print("---------------------------------------------")
--------------------------------------------- The final result is: 26.5 ---------------------------------------------
'''
Program: 2
Description: Lambdas defined in a loop with different values all return the same result.
Author: Tanu Nanda Prabhu
'''
squares = [] # Creating an empty list "squares"
for x in range(5):
squares.append(lambda n=x: n**2) # Lambda function, surf about it on the internet.
print("---------------------------------------------")
print(squares[4]())
print("---------------------------------------------")
--------------------------------------------- 16 ---------------------------------------------
'''
Program: 3
Description: String format() is the primary API method.
It takes a string and an arbitrary set of positional and keyword arguments.
Author: Tanu Nanda Prabhu
'''
print("---------------------------------------------")
print("[{0},{1},{2}]".format(1, 2, 3)) # Using the format() to format the string
print("---------------------------------------------")
--------------------------------------------- [1,2,3] ---------------------------------------------
'''
Program: 4
Description: String split() is the primary API method.
The split() method splits a string.
You can specify the separator, default separator is any whitespace
Author: Tanu Nanda Prabhu
'''
name = 'P Y T H O N'
print("---------------------------------------------")
updated_name = name.split() # Splitting the string 'P Y T H O N'
print(type(updated_name))
print("---------------------------------------------")
--------------------------------------------- <class 'list'> ---------------------------------------------
'''
Program: 5
Description: String slice is the primary API.
The string slice actually slices the string.
Usually represented in square brackets like []
Author: Tanu Nanda Prabhu
'''
name = 'P Y T H O N'
print("---------------------------------------------")
updated_name = name[::-1] # Slicing the string 'P Y T H O N'
print(updated_name)
print("---------------------------------------------")
--------------------------------------------- N O H T Y P ---------------------------------------------
'''
Program: 6
Description: Just playing with 'for' loops usign 'end'
Author: Tanu Nanda Prabhu
'''
print("---------------------------------------------")
for i in range(15, 20, 1):
print( i, end = ', ') # Playing with the 'for' loop with 'end'
print("\n---------------------------------------------")
--------------------------------------------- 15, 16, 17, 18, 19, ---------------------------------------------
'''
Program: 7
Description: List slicing: Used to slice the list based on the value,
provided inside the square brackets
Author: Tanu Nanda Prabhu
'''
print("---------------------------------------------")
new_list = [5, 10, 15, 25]
print(new_list[::-2]) # Using the concept of list slicing
print("---------------------------------------------")
--------------------------------------------- [25, 10] ---------------------------------------------
'''
Program: 8
Description: Concatenating values in a list using '+'
Author: Tanu Nanda Prabhu
'''
print("---------------------------------------------")
List = [x + y for x in ['Hello ', 'Good'] for y in ['Dear', 'Bye']]
print(List)
print("---------------------------------------------")
--------------------------------------------- ['Hello Dear', 'Hello Bye', 'GoodDear', 'GoodBye'] ---------------------------------------------
'''
Program: 9
Description: Joining the value of the list using 'join()'
Author: Tanu Nanda Prabhu
'''
List = ["Python", "Programming"]
print("---------------------------------------------")
print("-".join(List)) # Using join() to join the values in the list
print("---------------------------------------------")
--------------------------------------------- Python-Programming ---------------------------------------------
'''
Program: 10
Description: Converting values into 'integer' and 'round' at the same time
Author: Tanu Nanda Prabhu
'''
a = 5 # Integer values
b = 3
c1 = a/b
c1 = int(c1) # Type casting to integer
c2 = a/b
c2 = round(c2) # Rounding the value
if c1 == c2:
print("True")
else:
print("False")
False