كل الأمثلة

أمثلة

أوجد الخطأ في كود Python من سطرين

حلقة for تنقصها النقطتان: إيجاد الخطأ، ولماذا يتوقف Python قبل أن يطبع أي شيء، ثم السطر المصحَّح.

  • 0:45
  • مسائل البرمجة
  • بصوت Erinome
  • الإنجليزية

صُنع من فكرة

Find the error: for i in range(5) print(i)

التفريغ النصي للفيديو

In this video, we find and fix a Python syntax error.

Question one. Find the error: The first line reads for i in range, with five in parentheses. The indented second line reads print, with i in parentheses.

Notice that line one is missing a colon after the closing parenthesis. Python requires a colon at the end of a for loop header. Without it, Python raises a SyntaxError before either line executes, so nothing is printed.

The indentation of print is correct and does not need changing. Hence, the corrected first line is for i in range, open parenthesis, five, close parenthesis, colon.

موضوعك، مرسومًا في دقيقة تقريبًا.

أول 2 من فيديوهاتك مجانًا، مدة كلٍّ منها حتى دقيقة واحدة، مع علامة مائية. لا حاجة إلى بطاقة دفع. المنتج كاملًا، بكل الأصوات والأساليب.