Results 1 to 5 of 5

Thread: ปัญหา Python เรื่อง Input Raw_input

  1. #1
    Junior Member
    Join Date
    Jul 2006
    Location
    United States
    Posts
    3


    ปัญหา Python เรื่อง Input Raw_input

    คือแบบผมใช้ raw_input รับค่า แล้วแบบผมใช้ if เพื่อเช็ค พอค่าเป็นตัวเลขอ่ะครับผมก้ใช้ int(ตัวแปรที่รับraw_input) แปลง แต่มันไม่ยอมแปลงอ่าครับ ทำไงดีอ่าครับ

  2. #2
    Junior Member
    Join Date
    Jul 2006
    Location
    United States
    Posts
    3


    Re: ปัญหา Python เรื่อง Input Raw_input

    Example of code

    x=raw_input("Type 1:")
    if x=="1":
    int(x)
    else :
    print "Invalid Value"
    print type(x)

  3. #3
    Senior Member newsbot's Avatar
    Join Date
    Sep 2002
    Location
    Thailand
    Posts
    3,766


    Re: มีปัญหาอ่ะครับ ช่วยหน่อยครับ

    ลองดู Code ต่อไปนี้นะครับ

    [code]s = raw_input()

    try:

    clone 'em all

  4. #4
    Junior Member
    Join Date
    Jul 2006
    Location
    United States
    Posts
    3


    Re: ปัญหา Python เรื่อง Input Raw_input

    ขอบคุณมากครับ ผมแก้ชื่อกระทู้แล้วนะครับ แบบเพิ่งเข้ามาอ่ะครับ ขอโทดจริงๆครับ แบบงานมันด่วนมากเลยอ่ะครับ แล้วนั่งแก้แล้วมันไม่ได้ซะทีเลยงงอ่าครับ

    ยังไงก็ขอบคุณที่ช่วยนะครับ

  5. #5
    Senior Member
    Join Date
    Sep 2003
    Location
    Thailand
    Posts
    136


    Re: ปัญหา Python เรื่อง Input Raw_input

    การรับค่าจากแป้นคีย์บอร์ดมีสองคำสั่ง
    1. input() สำหรับรับข้อมูลตัวเลข
    2. raw_input() สำหรับรับข้อมูลตัวอักษร

    ปกติการรับค่า อาจเกิดความผิดพลาดจากการกดแป้น space bar ตามเข้ามาได้ เราต้อง strip มันก่อน กล่าวคือตัดให้เหลือเฉพาะข้อความที่พิมพ์เข้ามาเท่านั้น ด้วยคำสั่ง
    >>> from string import strip
    >>> m = raw_input("พิมพ์ 1: ")
    m = strip(m)
    หรืออาจจะใช้คำสั่ง
    m = m.strip() #ในกรณีที่ทราบชัดว่า m คือชนิดสตริง

    หรืออาจจะใช้คำสั่ง atoi() หมายถึง Ascii to Integer (จากอักขระเป็นตัวเลข)
    เช่น
    >>> from string import atoi, strip
    >>> m = atoi(strip(m))

    หรือ
    >> import string
    >> m = string.atoi(string.strip(m))
    หรือ
    >> m = string.atoi(m.strip())

    ภาษาไพธอนอนุญาตให้ทำในสิ่งเดียวกันได้หลายวิธีครับ !!
    http://202.28.33.44 (เอ็นโปรเท็คประเทศไทย)

Similar Threads

  1. คลิปสอนการ Input/Output Statement ภาษาC#
    By maitree2548 in forum C/C++,C#,VC++,MFC,Win32
    Replies: 1
    Last Post: 01-09-2009, 09:01 PM
  2. FCKeditor Input Sanitization Errors
    By newsbot in forum Exploits
    Replies: 0
    Last Post: 06-07-2009, 05:59 PM
  3. XSS beyond the web input
    By Gen0TypE in forum Hacking, Exploit Articles/Tutorial/Techniques
    Replies: 0
    Last Post: 02-07-2009, 12:38 AM
  4. Replies: 0
    Last Post: 26-05-2007, 09:40 PM
  5. Replies: 0
    Last Post: 01-01-1970, 07:00 AM

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •