-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
87 lines (66 loc) · 2.75 KB
/
main.py
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
# # Initialize an empty dictionary
# thisdict = {}
# # Collect information for three students
# for num in range(0, 3):
# keys = ["name", "surname", "age", "phone", "LineId", "sex"]
# student_info = {}
# for key in keys:
# value = input(f"{key} for Student {num}: ")
# student_info[key] = value
# thisdict[f"Student {num}"] = student_info
# # Print the collected information
# print("--------------------")
# for student, info in thisdict.items():
# print(f"{student}:")
# for key, value in info.items():
# print(f" {key} : {value}")
# print("--------------------")
# -------------------------------------------------------------------------------------------
# Code อาจารย์ Array and Dictionary
# x = [{} , {} , {}]
# for i in range(3):
# x[i].update({
# "name": input("name: "),
# "surname": input("surname: "),
# "age": input("age: "),
# "phone": input("phone: "),
# "lineID": input("Line ID: "),
# "sex": input("sex: ")
# })
# print("------")
# for i in range(3):
# print(f"Student name: {x[i]['name']}, Surname: {x[i]['surname']}, Age: {x[i]['age']}, Phone: {x[i]['phone']}, Line ID: {x[i]['lineID']}, Sex: {x[i]['sex']}")
# # Code By Phuwaset ย่อโดยใช้โค้ดสั้นลงและกระชับขึ้นได้โดยใช้ฟังก์ชัน zip และการวนลูปผ่านรายการของคีย์ เพื่ออัปเดตข้อมูลในแต่ละ dictionary ใน x:
# fields = ["name", "surname", "age", "phone", "lineID", "sex"]
# x = [{} for _ in range(3)]
# for i in range(3):
# for field in fields:
# x[i][field] = input(f"{field}: ")
# print("------")
# for student in x:
# print(", ".join(f"{key.capitalize()}: {value}" for key, value in student.items()))
# Function to process command and parameter
def process_command(command_input):
# Convert to lowercase, strip whitespace, and slice to separate command and parameter
command_input = command_input.lower().strip()
cmd, para = command_input.split(',')
cmd = cmd.strip()
para = para.strip()
# Show results based on command
if cmd == 'on':
print(f"cmd = {cmd}")
print(f"para = {para}")
print(f"Run On => {para}")
elif cmd == 'off':
print(f"cmd = {cmd}")
print(f"para = {para}")
print(f"Run Off => {para}")
else:
print("Unknown command")
print(f"cmd = {cmd}")
print(f"para = {para}")
# Example usage
input_str1 = input("Command (3), paramitor (2) : ")
process_command(input_str1)
input_str2 = input("Command (3), paramitor (2) : ")
process_command(input_str2)