-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mechine.py
41 lines (33 loc) · 2.35 KB
/
Mechine.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
Mechine = []
for i in range(2):
name = input(f"Name{i} : ")
temp = input(f"Temp{i} : ")
volt = input(f"Volt{i} : ")
amp = input(f"Amp{i} : ")
# append = update
Mechine.append({"name": name, "Temp": temp, "Volt": volt, "Amp": amp})
for i in Mechine:
print(f"Name: {i['name']} \nTemp: {i['Temp']} \nVolt: {i['Volt']} \nAmp: {i['Amp']}")
print("------------")
# # สร้างลิสต์สำหรับเก็บข้อมูลของเครื่องจักร
# Mechine = []
# # วนลูปเพื่อรับข้อมูล 2 เครื่อง
# for i in range(2):
# # รับข้อมูลจากผู้ใช้
# name = input(f"Name{i} : ")
# temp = input(f"Temp{i} : ")
# volt = input(f"Volt{i} : ")
# amp = input(f"Amp{i} : ")
# # เก็บข้อมูลที่รับมาในรูปแบบ dictionary และเพิ่มเข้าไปในลิสต์
# Mechine.append({"name": name, "Temp": temp, "Volt": volt, "Amp": amp})
# # วนลูปเพื่อแสดงผลข้อมูลที่เก็บในลิสต์
# for i in Mechine:
# print(f"Name: {i['name']} \nTemp: {i['Temp']} \nVolt: {i['Volt']} \nAmp: {i['Amp']}")
# print("------------")
# อธิบายเพิ่มเติมเกี่ยวกับคำสั่ง:
# Mechine = []: สร้างลิสต์ว่างชื่อ Mechine เพื่อเก็บข้อมูลของเครื่องจักรแต่ละตัว
# for i in range(2):: ใช้ลูป for เพื่อวนซ้ำสองครั้ง (สำหรับเครื่องจักร 2 เครื่อง)
# input(...): รับข้อมูลจากผู้ใช้ในแต่ละรอบของลูป
# Mechine.append(...): เพิ่มข้อมูลที่รับมา (ในรูปแบบของ dictionary) ลงในลิสต์ Mechine
# for i in Mechine:: วนลูปอีกครั้งเพื่อนำข้อมูลในลิสต์ Mechine มาแสดงผล
# print(...): แสดงผลข้อมูลของเครื่องจักรในรูปแบบที่เป็นระเบียบ