البرمجة

ترتيب عشوائي لأسئلة الاختبار: تحسين برمجة الأمان عبر الإنترنت

في محاولتك لجعل الأسئلة في الاختبار تظهر بترتيب عشوائي، وجدت أنك استخدمت دالة shuffle بشكل صحيح لخلط الأسئلة. ومع ذلك، هناك بعض الأخطاء في الترتيب والتهوية في الشيفرة التي يمكنني مساعدتك في تصحيحها. دعني أقوم بتحليل الشيفرة وتقديم بعض التوجيهات:

  1. أولاً وقبل البدء في حل المشكلة، تأكد من تصحيح التهوية في الشيفرة. قد يؤدي تهوئة غير صحيحة إلى سلوك غير متوقع.

  2. لاحظ أنك استخدمت elif بعد else في كتلة الشرط الخاصة بك، مما يمكن أن يؤدي إلى خطأ في التهوية. يفضل استخدام elif مباشرة بعد if دون وجود else بينهما.

  3. استخدم معرفة أنك قد قمت بتعريف قائمة الأسئلة (questions) باستخدام أرقام، ولكن عند التحقق من الشرط (if questions == 0:)، يجب عليك استخدام if 0 in questions: بدلاً من ذلك.

  4. احرص على تصحيح التهوية بشكل صحيح، خاصة في تسجيل الأسئلة والإجابات.

  5. يجب عليك استخدام elif بشكل صحيح بدلاً من if عند فحص الفهرس في القائمة.

الشيفرة المصححة قد تبدو كالتالي:

python
print("Transferring you to the quiz...") print("Rules: ") print("This quiz features questions about online safety. The questions are multiple choice so enter the number which corresponds to your answer. For every question you get right you will get a point. Good luck!") score = 0 goes = 0 questions = [0, 1, 2, 3, 4] import random random.shuffle(questions) print(questions) while goes < 5: current_question = questions[goes] if current_question == 0: q1 = input("What is CEOP? 1.Child Exploitation and Online Protection 2.Criminal Exploration and Online Protection 3.Child Exploitation and Organised Protectors: ") if q1 == "1": print("That's right, well done!") score += 1 else: print("That's wrong, unlucky!") goes += 1 elif current_question == 1: q2 = input("When you get an email from someone you do not know, what should you do? 1.Reply and say hello 2.Forward to your friends 3.Delete it and mark as spam: ") if q2 == "3": print("That's right, well done!") score += 1 else: print("That's wrong, unlucky!") goes += 1 elif current_question == 2: q3 = input("How secret should you keep your passwords? 1.Give them only to your best friends 2.Never give out passwords except to your parents 3.Give them to strangers: ") if q3 == "2": print("That's right, well done!") score += 1 else: print("That's wrong, unlucky!") goes += 1 elif current_question == 3: q4 = input("When an online contact who frightens you asks to meet you in person what should you do? 1.Arrange to meet them 2.Arrange to meet them with your best friend 3.Report to CEOP: ") if q4 == "3": print("That's right, well done!") score += 1 else: print("That's wrong, unlucky!") goes += 1 elif current_question == 4: q5 = input("If an email asks you to enter your bank account details because of a problem with your account what should you do? 1.Contact the bank to check if they sent the email 2.Reply to the email 3.Enter your bank account details: ") if q5 == "1": print("That's right, well done!") score += 1 else: print("That's wrong, unlucky!") goes += 1 print("End of quiz") print("Well done, your score was {0}".format(score))

تأكد من تحليل الشيفرة وتشغيلها لرؤية إذا كانت تلبي احتياجاتك بشكل صحيح.

المزيد من المعلومات

في محاولتك لتحقيق ترتيب عشوائي للأسئلة في الاختبار، تم استخدام الدالة shuffle بشكل صحيح لخلط القائمة التي تحتوي على أرقام الأسئلة. ومع ذلك، كان هناك بعض الأخطاء في الترتيب والهيكل البرمجي تم تصحيحها.

قمت بتقديم توجيهات حول كيفية تصحيح الشيفرة بما في ذلك تصحيح التهوية واستخدام الهيكل الصحيح للشرط. يجب عليك أيضًا أن تتأكد من استخدام elif بشكل صحيح لفحص القيمة الحالية للسؤال في القائمة.

إذا كنت بحاجة إلى المزيد من المعلومات حول كيفية تحسين الشيفرة أو توسيع البرنامج بشكل عام، يمكنني مساعدتك. هل لديك أي أسئلة محددة أو تحديثات إضافية تحتاج إلى دعم؟

مقالات ذات صلة

زر الذهاب إلى الأعلى
إغلاق

أنت تستخدم إضافة Adblock

يرجى تعطيل مانع الإعلانات حيث أن موقعنا غير مزعج ولا بأس من عرض الأعلانات لك فهي تعتبر كمصدر دخل لنا و دعم مقدم منك لنا لنستمر في تقديم المحتوى المناسب و المفيد لك فلا تبخل بدعمنا عزيزي الزائر