-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_Tuples_sets_subprocess_lists_ASCII.py
More file actions
72 lines (46 loc) · 1.53 KB
/
Copy pathpython_Tuples_sets_subprocess_lists_ASCII.py
File metadata and controls
72 lines (46 loc) · 1.53 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
# ============================================
# Task 1 — Tuples
# ============================================
# Create tuple
cities = ("Hyderabad", "Bangalore", "Chennai", "Mumbai", "Delhi")
# Unpack tuple
c1, c2, c3, c4, c5 = cities
# Print variables
print(c1)
print(c2)
print(c3)
print(c4)
print(c5)
# Try modifying tuple
try:
cities[0] = "Pune"
except TypeError as e:
print("Error: Tuples are immutable and cannot be modified.")
print("\n============================================\n")
# ============================================
# Task 2 — Sets
# ============================================
python_passed = {"Ajay", "Ravi", "Sneha", "Kiran"}
sql_passed = {"Sneha", "Kiran", "Amit", "Neha"}
# Union
print("Union:", python_passed | sql_passed)
# Intersection
print("Intersection:", python_passed & sql_passed)
# Difference (Python-only)
print("Python-only:", python_passed - sql_passed)
print("\n============================================\n")
# ============================================
# Task 3 — Lists and ASCII
# ============================================
ascii_values = [65, 66, 67, 68, 69]
for val in ascii_values:
print(f"{val} -> {chr(val)}")
# ASCII of 'Z'
print("ASCII of 'Z':", ord('Z'))
print("\n============================================\n")
# ============================================
# Task 4 — Subprocess
# ============================================
import subprocess
result = subprocess.run(["whoami"], capture_output=True, text=True)
print("Current user:", result.stdout.strip())