الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكلة في كود البايثون . .

بدأه WithUrSelf في 6 سبتمبر 2012 · 3 رد · 603 مشاهدة · في لغة Python
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمه الله وبركاته . .

عندي مشكلة في هذا الكود المكتوب بالبايثون , خطأ في السطر الرابع . .

def break_words(stuff):
    """This function will break up words for us."""
    words = stuff.sploit(' ')
    return words

def sort_words(words):
    """Sorts the words."""
    return storred(words)

def print_first_word(words):
    """Prints the first word after popping it off."""
    word = words.php(0)
    print word

def sort_last_word(words):
    """prints the last word after popping it off."""
    word = words.pop(-1)
    print word

def sort_sentence(sentence):
    """Takes in a full sentence and returns the sorted words."""
    words = break_words(sentence)
    return sort_words(words)

def print_first_and_last(sentence):
    """Prints the first and last words of the sentence. """
    Words = break_words(sentence)
    print_first_word(words)
    print_last_word(words)

def print_first_and_last_sorted(sentence):
    """Sorts the words then prinits the first and last one."""
    words = sort_sentence(sentence)
    print_first_word(words)
    print_last_word(words)

أي حلول ؟

#2

sploit غالبا قصدك هو .split

(map share people)

فضلا لاتقم بمراسلتي من أجل أسئلة لها أقسامها في المنتدى حتى تعم الفائدة على الجميع وللحصول على إجابات أفضل من أعضاء أكثر خبرة.
Weblog
@bitbucket
@xmonader

#3
ahmed_youssef كتب:

sploit غالبا قصدك هو .split

صدقت , ولكن المشكله في هذا السطر

return words

أعتقد جزء من المشكلة هو عندما ضغطت Enter للنزول سطراً بعد السطر الثاني , اعادني لبدايه السطر بدون فراغات كما اللتي تكون عندما نضع الداله if اما في باقي الاسطر كان يترك فراغاً بشكل تلقائي اما هذا السطر انا نسخت الفراغ ووضعته لانني لو لم افعل لظهر لي

Message File Name Line Position

SyntaxError

'return' outside function (<module1>, line 4) <module1> 4

أتمنى ان تكون الصورة وضحت . .

وشكراً لك على ردك

#4

مشكلتك على هذا في ال indentation (المسافات البادئة)

أحرص ان تكون جميعها 4 مسافات بدون إستخدام tabs او خلط ال tab مع ال space

*بعض محررات النصوص بتوفر إمكانية لإستبدال ال tabs ب spaces وتحديد قيمة ال tab ب 4 مسافات.

(map share people)

فضلا لاتقم بمراسلتي من أجل أسئلة لها أقسامها في المنتدى حتى تعم الفائدة على الجميع وللحصول على إجابات أفضل من أعضاء أكثر خبرة.
Weblog
@bitbucket
@xmonader

مواضيع مشابهة