It looks like you have an indentation error in your Python code. Python uses indentation to define the structure of the code, so it’s important to ensure that all lines within the same block have the same level of indentation. In your code, the else
statement should be at the same level of indentation as the if
statement. Here’s the corrected code:
pythonpassword = "test123"
if password == raw_input('What is the password?'):
print("Access given")
else:
print("Access forbidden")
In this corrected code, both the if
and else
statements are indented with the same level of spaces (usually four spaces), which is the standard convention in Python.
-
عد الأسطر في Python11/03/2024
-
فحص الأعداد المربعية في Python30/03/2024
المزيد من المعلومات
بالطبع! في لغة Python، تُستخدم الهوامش (المسافات الفارغة) لتنظيم الشفرة بدلاً من الأقواس أو الكلمات الرئيسية كما هو الحال في لغات أخرى. هذا يعني أنه يجب أن تكون الهوامش متناسقة في كل جزء من الشفرة الخاصة بك. على سبيل المثال، اعتبر الكود التالي:
pythonif x == 1:
print("x is 1")
في هذا المثال، إذا كان x
يساوي 1، سيتم طباعة "x is 1"
، ولكنه سيقوم بإثارة خطأ بسبب انحراف التبويب. لحل هذا، يجب أن تُضاف الفراغات اللازمة:
pythonif x == 1:
print("x is 1")
إذا كان لديك أي أسئلة أو احتياجات لمزيد من التوضيح، فلا تتردد في طرحها!