Lesson 6: Basics of Python
1. Variables and Data Types:
- string: name = "John"
- int: age = 18
- float: percentage = 92.5
- bool: is_passed = True
2. Input and Output:
- input(): used to take input from user
- print(): used to display output
3. Arithmetic Operations:
- +, -, *, /, %, **
4. Conditional Statements:
- if, elif, else
Example:
if marks >= 33:
print("Pass")
else:
print("Fail")
5. Loops:
- for loop: used for fixed number of iterations
Example:
for i in range(5):
print(i)
Lesson 7: Functions in Python
1. What is a Function?
A function is a block of code which only runs when it is called.
2. Defining a Function:
def function_name(parameters):
statements
3. Calling a Function:
function_name(arguments)
4. Returning a Value:
- return keyword is used
Example 1:
def area(x, y):
return x * y
x = int(input("Enter length: "))
y = int(input("Enter breadth: "))
print("Area is:", area(x, y))
Example 2 (Greater of 3 numbers):
def greater(x, y, z):
if x > y and x > z:
return f"{x} is greater"
elif y > x and y > z:
return f"{y} is greater"
else:
return f"{z} is greater"
x = int(input("Enter first number: "))
y = int(input("Enter second number: "))
z = int(input("Enter third number: "))
print(greater(x, y, z))