รูปแบบการเขียน Python 3 เบี้องต้น
Hello worldโค้ด
print ("Hello world")
ผลลัพธ์| Hello world ใน Python 3 |
จะเห็นได้ว่ารูปแบบการเขียน Python 3 จะง่าย ๆ ครับ
โปรแกรมบวกลบเลขอย่างง่าย
โปรแกรมนี้ใช้หลักการโดยรับค่ามา แล้วใช้ if else ครับ แล้วหาผลลัพท์
#!/usr/bin/python
#-*-coding: utf-8 -*-
print ("Program + or -")
print ("Build by Wannaphong")
print ("18/10/2013")
print ("1.+ 2. -")
x = int(input("input: "))
if x == 1:
a = int(input("input1: "))
b = int(input("input2: "))
print ("=" , a + b)
elif x == 2:
c = int(input("input1: "))
d = int(input("input2: "))
print ("=" , c - d)
elif x < 1 or x > 2:
print ("No!. You input'n 1 or 2.")
ผลลัพธ์
| โปรแกรมบวกลบเลขอย่างง่าย |
จะเห็นว่า รูปแบบการเขียนของ Python 3 จะง่ายต่อการเข้าใจโค้ดครับ หากผู้อ่านเขียน C มาก่อนจะพบว่า Python 3 สะดวกสบายและง่ายกว่าครับ ส่วนประสิทธิภาพคงสู้ภาษา C ไม่ได้ครับ
ขอบคุณครับ

0 ความคิดเห็น:
แสดงความคิดเห็น
แสดงความคิดเห็นได้ครับ :)