Tags:
Forums: 

คือว่าผมเป็นมือใหม่ python เพิ่งศึกษาได้ไม่กี่ชั่วโมงวันนี้เลยลองเขียนโปรแกรมเล่นๆ

def outputconvert ():
print '1.Meter to Mile program'
print '2.Mile to Meter program'
print '3.Centimeter to Inch'
print '4.Inch to Centimeter'
def outputconsole ():
print outputconvert ()
inputconvert = input('type here what can i help you')
if (inputconvert == 1):
metomi = input('meter here')
print metomi *5.00000 /8.00000
input('Please any key for exit')
elif (inputconvert ==2):
mitome = input ('mile here')
print mitome / 1.6
input('Please any key for exit')
elif (inputconvert ==3):
centoin = input('Centimeter here')
print centoin * 0.39400
input('Please any key for exit')
elif (inputconvert ==4):
intocen = input('Inch here')
print intocen * 2.54
input('Please any key for exit')
else :
print 'you mau'
outputconsole ()

outputconsole ()

แบบนี้ (ผมเขียนชื่อตัวแปรผิดอย่าว่ากันนะมั่วเอา)แต่ว่าตอนแสดงผมมันมีคำว่า none ด้วย แบบนี้ มันคืออะไรแก้ยังไง ผมทำอะไรผิดครับ มันคาใจ

1.Meter to Mile program
2.Mile to Meter program
3.Centimeter to Inch
4.Inch to Centimeter
None<<<<<<<<<<<<<<<<<<<<<<<<<<ตรงนี้นิ
type here what can i help you

ขอบคุณล่วงหน้านะครับ

Get latest news from Blognone
By: anu
Contributor
on 12 October 2012 - 02:04 #489067
def outputconvert ():
    print '1.Meter to Mile program'
    print '2.Mile to Meter program'
    print '3.Centimeter to Inch'
    print '4.Inch to Centimeter'
def outputconsole ():
    print outputconvert ()
    inputconvert = input('type here what can i help you')
    if (inputconvert == 1):
        metomi = input('meter here')
        print metomi *5.00000 /8.00000
        input('Please any key for exit')
    elif (inputconvert ==2):
        mitome = input ('mile here')
        print mitome / 1.6
        input('Please any key for exit')
    elif (inputconvert ==3):
        centoin = input('Centimeter here')
        print centoin * 0.39400
        input('Please any key for exit')
    elif (inputconvert ==4):
        intocen = input('Inch here')
        print intocen * 2.54
        input('Please any key for exit')
    else :
        print 'you mau'
        outputconsole ()

outputconsole ()

บรรทัดที่ 7 สั่งแค่ outputconvert () ก็แสดงข้อความแล้ว หากไปสั่ง print outputconvert () มันจะพิมพ์ข้อความที่ตอบกลับจากฟังก์ชั่น outputconvert () ซึ่งในที่นี้เราไม่ได้ return อะไรกลับ มันเลยขึ้นเป็น none

การโพสโค้ดให้เลือก Input format เป็น html แล้วใส่ <pre> ครอบไว้

By: saratlim
ContributorAndroid
on 12 October 2012 - 18:59 #489411
saratlim's picture

ขอบคุณครับ มือใหม่จริงๆ


blog