-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.py
More file actions
87 lines (71 loc) · 2.39 KB
/
examples.py
File metadata and controls
87 lines (71 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
Python Examples - Basic Programming Concepts
This script demonstrates fundamental Python concepts including:
- Loops and conditionals
- Input/output operations
- Functions and parameters
"""
# ============================================================================
# Example 1: Print Even Numbers (1-10)
# ============================================================================
print("=" * 70)
print("Example 1: Print Even Numbers from 1 to 10")
print("=" * 70)
for i in range(1, 11):
if i % 2 == 0:
print(i)
print() # Blank line for readability
# ============================================================================
# Example 2: Age-Based Access Control
# ============================================================================
print("=" * 70)
print("Example 2: Age-Based Access Control")
print("=" * 70)
age = int(input("Enter age: "))
if age >= 18:
print("Access Granted")
else:
print("Access Denied")
print() # Blank line for readability
# ============================================================================
# Example 3: Score Validation (0-100 range)
# ============================================================================
print("=" * 70)
print("Example 3: Score Validation")
print("=" * 70)
score = 85
if score >= 0 and score <= 100:
print("Valid Score")
else:
print("Invalid Score")
print() # Blank line for readability
# ============================================================================
# Example 4: Function with Parameters
# ============================================================================
print("=" * 70)
print("Example 4: Greeting Function")
print("=" * 70)
def greet(name, age):
"""
Greet a person with their name and age.
Args:
name (str): The person's name
age (int): The person's age
Returns:
None
"""
print(f"Hello {name}, you are {age}")
greet("Alice", 25) # "Alice" goes to name, 25 goes to age
print() # Blank line for readability
# ============================================================================
# Example 5: Extended Function Usage
# ============================================================================
print("=" * 70)
print("Example 5: Extended Function Usage")
print("=" * 70)
greet("Bob", 30)
greet("Charlie", 22)
print() # Blank line for readability
print("=" * 70)
print("All examples completed successfully!")
print("=" * 70)