Skip to content

Commit 5b1cfbd

Browse files
committed
Merge branch 'feat/ash' of https://github.com/Ashish-Kumar-Dash/Python-Basics-to-Advanced into Ashish-Kumar-Dash-feat/ash
New commit
2 parents b479a8c + a3592b7 commit 5b1cfbd

File tree

5 files changed

+192
-0
lines changed

5 files changed

+192
-0
lines changed
File renamed without changes.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Title: Python Control Structures Tutorial
3+
Author: Python-Basics-to-Advanced Contributors
4+
Difficulty: Beginner
5+
Description: Detailed guide to if-else, loops, break, continue, and control flow in Python
6+
Date: October 2025
7+
"""
8+
9+
print("=== Python Control Structures Tutorial ===\n")
10+
11+
# =============================================================================
12+
# 1. CONDITIONAL STATEMENTS
13+
# =============================================================================
14+
15+
number = int(input("Enter a number: "))
16+
17+
if number > 0:
18+
print("The number is positive.")
19+
elif number == 0:
20+
print("The number is zero.")
21+
else:
22+
print("The number is negative.")
23+
24+
# =============================================================================
25+
# 2. FOR LOOP
26+
# =============================================================================
27+
28+
print("\nCounting from 1 to 5:")
29+
for i in range(1, 6):
30+
print(i)
31+
32+
# =============================================================================
33+
# 3. WHILE LOOP
34+
# =============================================================================
35+
36+
print("\nCounting down from 5 to 1:")
37+
count = 5
38+
while count > 0:
39+
print(count)
40+
count -= 1
41+
42+
# =============================================================================
43+
# 4. BREAK STATEMENT
44+
# =============================================================================
45+
46+
print("\nFinding the first number divisible by 3 between 10 and 20:")
47+
for num in range(10, 21):
48+
if num % 3 == 0:
49+
print(f"Found: {num}")
50+
break
51+
52+
# =============================================================================
53+
# 5. CONTINUE STATEMENT
54+
# =============================================================================
55+
56+
print("\nPrinting numbers between 1 and 10 skipping multiples of 3:")
57+
for num in range(1, 11):
58+
if num % 3 == 0:
59+
continue
60+
print(num)
61+
62+
print("\n=== End of Control Structures Tutorial ===")
63+
print("Practice tip: Modify the range and conditions to see different outputs and behaviors.")
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
"""
2+
Title: Python Functions Tutorial
3+
Author: Python-Basics-to-Advanced Contributors
4+
Difficulty: Beginner
5+
Description: Comprehensive guide to defining and using functions in Python with examples
6+
Date: October 2025
7+
"""
8+
9+
# =============================================================================
10+
# 1. DEFINING FUNCTIONS
11+
# =============================================================================
12+
13+
print("=== Python Functions Tutorial ===\n")
14+
15+
def greet(name):
16+
"""
17+
Greets a person by name.
18+
19+
Args:
20+
name (str): The person's name.
21+
22+
Returns:
23+
str: Greeting message.
24+
"""
25+
return f"Hello, {name}!"
26+
27+
print(greet("Alice"))
28+
29+
# =============================================================================
30+
# 2. FUNCTION PARAMETERS AND DEFAULTS
31+
# =============================================================================
32+
33+
def power(base, exponent=2):
34+
"""
35+
Calculates the power of a base number.
36+
37+
Args:
38+
base (int or float): Base number.
39+
exponent (int or float): Exponent, default is 2.
40+
41+
Returns:
42+
int or float: Result of base raised to exponent.
43+
"""
44+
return base ** exponent
45+
46+
print(f"5^2 = {power(5)}")
47+
print(f"3^3 = {power(3, 3)}")
48+
49+
# =============================================================================
50+
# 3. RETURNING MULTIPLE VALUES
51+
# =============================================================================
52+
53+
def arithmetic_ops(a, b):
54+
"""
55+
Performs basic arithmetic operations on two numbers.
56+
57+
Args:
58+
a (int or float): First number.
59+
b (int or float): Second number.
60+
61+
Returns:
62+
tuple: Sum, difference, product, and quotient.
63+
"""
64+
sum_ = a + b
65+
diff = a - b
66+
prod = a * b
67+
quo = a / b if b != 0 else None
68+
return sum_, diff, prod, quo
69+
70+
s, d, p, q = arithmetic_ops(10, 5)
71+
print(f"Sum: {s}, Difference: {d}, Product: {p}, Quotient: {q}")
72+
73+
# =============================================================================
74+
# 4. LAMBDA (ANONYMOUS) FUNCTIONS
75+
# =============================================================================
76+
77+
add = lambda x, y: x + y
78+
square = lambda x: x * x
79+
80+
print(f"Add 3 + 4 = {add(3, 4)}")
81+
print(f"Square of 6 = {square(6)}")
82+
83+
# =============================================================================
84+
# 5. FUNCTION SCOPE AND LOCAL VARIABLES
85+
# =============================================================================
86+
87+
def demonstrate_scope():
88+
x = 10 # local variable
89+
print(f"Inside function, x = {x}")
90+
91+
demonstrate_scope()
92+
# print(x) # This would raise an error because x is local
93+
94+
print("\n=== End of Functions Tutorial ===")
95+
print("Practice tip: Try creating your own functions and experimenting with parameters and returns!")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Title: Simple Calculator
3+
Author: Python-Basics-to-Advanced
4+
Difficulty: Beginner
5+
Description: Basic calculator supporting +, -, *, / operations with input validation
6+
"""
7+
8+
def calculator():
9+
print("Simple Calculator")
10+
try:
11+
a = float(input("Enter first number: "))
12+
b = float(input("Enter second number: "))
13+
except ValueError:
14+
print("Invalid input. Please enter numeric values.")
15+
return
16+
17+
op = input("Choose operation (+, -, *, /): ")
18+
19+
if op == '+':
20+
print(f"Result: {a + b}")
21+
elif op == '-':
22+
print(f"Result: {a - b}")
23+
elif op == '*':
24+
print(f"Result: {a * b}")
25+
elif op == '/':
26+
if b == 0:
27+
print("Error: Cannot divide by zero")
28+
else:
29+
print(f"Result: {a / b}")
30+
else:
31+
print("Invalid operation")
32+
33+
if __name__ == "__main__":
34+
calculator()

0 commit comments

Comments
 (0)