Hướng dẫn how do you make a quiz in python? - Làm thế nào để bạn thực hiện một câu đố trong python?

Mã số

Copyclass Question:
     def __init__[self, prompt, answer]:
          self.prompt = prompt
          self.answer = answer

question_prompts = [
     "What color are apples?\n[a] Red/Green\n[b]Orange",
     "What color are bananas?\n[a] Red/Green\n[b]Yellow",
]

questions = [
     Question[question_prompts[0], "a"],
     Question[question_prompts[1], "b"],
]

def run_quiz[questions]:
     score = 0
     for question in questions:
          answer = input[question.prompt]
          if answer == question.answer:
               score += 1
     print["you got", score, "out of", len[questions]]

run_quiz[questions]

Xin chào tất cả mọi người, hôm nay chúng tôi sẽ tạo ra một trò chơi đố vui trong Python.Quiz Game in python.

Làm thế nào nó hoạt động?

Trò chơi đố của chúng tôi sẽ đặt câu hỏi cho người chơi mà người chơi phải trả lời với câu trả lời đúng. Mỗi câu hỏi sẽ có 3 lần thử. Nếu người chơi không trả lời câu hỏi trong vòng 3 lần thì trò chơi sẽ chuyển sang câu hỏi tiếp theo và người chơi sẽ nhận được điểm bằng không. Nhưng nếu người chơi đưa ra câu trả lời đúng cho câu hỏi sau đó, anh ta sẽ nhận được 1 điểm. Vào cuối trò chơi, tổng số điểm được ghi bởi người chơi được hiển thị.

Tôi hy vọng hoạt động trừu tượng của trò chơi là rõ ràng cho mọi người, bây giờ chúng ta hãy chuyển sang thiết lập dự án.

Thiết lập dự án

Trước khi chúng tôi bắt đầu mã hóa dự án này, chúng tôi cần một số câu hỏi và câu trả lời cho trò chơi của chúng tôi.

Trong trường hợp của chúng tôi, chúng tôi sẽ sử dụng một số câu hỏi dựa trên siêu anh hùng dễ dàng.

Hãy sử dụng câu hỏi hoặc câu trả lời của riêng bạn cho trò chơi. Câu hỏi và câu trả lời của chúng tôi sẽ được lưu trữ trong một tệp Python riêng biệt dưới dạng từ điển Python.python dictionary.

Đây trông như thế nào:

quiz = {
    1 : {
        "question" : "What is the first name of Iron Man?",
        "answer" : "Tony"
    },
    2 : {
        "question" : "Who is called the god of lightning in Avengers?",
        "answer" : "Thor"
    },
    3 : {
        "question" : "Who carries a shield of American flag theme in Avengers?",
        "answer" : "Captain America"
    },
    4 : {
        "question" : "Which avenger is green in color?",
        "answer" : "Hulk"
    },
    5 : {
        "question" : "Which avenger can change it's size?",
        "answer" : "AntMan"
    },
    6 : {
        "question" : "Which Avenger is red in color and has mind stone?",
        "answer" : "Vision"
    }
}

Nhập chế độ FullScreenen EXIT Mode FullScreen

Bạn có thể tìm hiểu thêm về từ điển Python từ đây.python dictionaries from here.

Chúng tôi sẽ không thể bao gồm nhiều về từ điển trong hướng dẫn này nhưng về cơ bản, đó là một cấu trúc dữ liệu có thể được sử dụng để lưu trữ dữ liệu như một hình thức duy nhất, có tổ chức và dễ truy cập.

Bạn có thể nghĩ về từ điển như danh sách. Nhưng có một số khác biệt chính giữa danh sách & từ điển:

  • Danh sách được bao quanh trong dấu ngoặc đơn trong khi các từ điển được đặt trong các dấu ngoặc
    quiz = {
        1 : {
            "question" : "What is the first name of Iron Man?",
            "answer" : "Tony"
        },
        2 : {
            "question" : "Who is called the god of lightning in Avengers?",
            "answer" : "Thor"
        },
        3 : {
            "question" : "Who carries a shield of American flag theme in Avengers?",
            "answer" : "Captain America"
        },
        4 : {
            "question" : "Which avenger is green in color?",
            "answer" : "Hulk"
        },
        5 : {
            "question" : "Which avenger can change it's size?",
            "answer" : "AntMan"
        },
        6 : {
            "question" : "Which Avenger is red in color and has mind stone?",
            "answer" : "Vision"
        }
    }
    
    3.
    quiz = {
        1 : {
            "question" : "What is the first name of Iron Man?",
            "answer" : "Tony"
        },
        2 : {
            "question" : "Who is called the god of lightning in Avengers?",
            "answer" : "Thor"
        },
        3 : {
            "question" : "Who carries a shield of American flag theme in Avengers?",
            "answer" : "Captain America"
        },
        4 : {
            "question" : "Which avenger is green in color?",
            "answer" : "Hulk"
        },
        5 : {
            "question" : "Which avenger can change it's size?",
            "answer" : "AntMan"
        },
        6 : {
            "question" : "Which Avenger is red in color and has mind stone?",
            "answer" : "Vision"
        }
    }
    
    2
    parenthesis while dictionaries are enclosed in
    quiz = {
        1 : {
            "question" : "What is the first name of Iron Man?",
            "answer" : "Tony"
        },
        2 : {
            "question" : "Who is called the god of lightning in Avengers?",
            "answer" : "Thor"
        },
        3 : {
            "question" : "Who carries a shield of American flag theme in Avengers?",
            "answer" : "Captain America"
        },
        4 : {
            "question" : "Which avenger is green in color?",
            "answer" : "Hulk"
        },
        5 : {
            "question" : "Which avenger can change it's size?",
            "answer" : "AntMan"
        },
        6 : {
            "question" : "Which Avenger is red in color and has mind stone?",
            "answer" : "Vision"
        }
    }
    
    3
    brackets.
  • Các phần tử riêng lẻ của danh sách được truy cập bằng cách sử dụng
    quiz = {
        1 : {
            "question" : "What is the first name of Iron Man?",
            "answer" : "Tony"
        },
        2 : {
            "question" : "Who is called the god of lightning in Avengers?",
            "answer" : "Thor"
        },
        3 : {
            "question" : "Who carries a shield of American flag theme in Avengers?",
            "answer" : "Captain America"
        },
        4 : {
            "question" : "Which avenger is green in color?",
            "answer" : "Hulk"
        },
        5 : {
            "question" : "Which avenger can change it's size?",
            "answer" : "AntMan"
        },
        6 : {
            "question" : "Which Avenger is red in color and has mind stone?",
            "answer" : "Vision"
        }
    }
    
    4 của phần tử trong khi các phần tử riêng lẻ của từ điển được truy cập thông qua cặp
    quiz = {
        1 : {
            "question" : "What is the first name of Iron Man?",
            "answer" : "Tony"
        },
        2 : {
            "question" : "Who is called the god of lightning in Avengers?",
            "answer" : "Thor"
        },
        3 : {
            "question" : "Who carries a shield of American flag theme in Avengers?",
            "answer" : "Captain America"
        },
        4 : {
            "question" : "Which avenger is green in color?",
            "answer" : "Hulk"
        },
        5 : {
            "question" : "Which avenger can change it's size?",
            "answer" : "AntMan"
        },
        6 : {
            "question" : "Which Avenger is red in color and has mind stone?",
            "answer" : "Vision"
        }
    }
    
    5 trong đó
    quiz = {
        1 : {
            "question" : "What is the first name of Iron Man?",
            "answer" : "Tony"
        },
        2 : {
            "question" : "Who is called the god of lightning in Avengers?",
            "answer" : "Thor"
        },
        3 : {
            "question" : "Who carries a shield of American flag theme in Avengers?",
            "answer" : "Captain America"
        },
        4 : {
            "question" : "Which avenger is green in color?",
            "answer" : "Hulk"
        },
        5 : {
            "question" : "Which avenger can change it's size?",
            "answer" : "AntMan"
        },
        6 : {
            "question" : "Which Avenger is red in color and has mind stone?",
            "answer" : "Vision"
        }
    }
    
    6 là mã định danh và
    quiz = {
        1 : {
            "question" : "What is the first name of Iron Man?",
            "answer" : "Tony"
        },
        2 : {
            "question" : "Who is called the god of lightning in Avengers?",
            "answer" : "Thor"
        },
        3 : {
            "question" : "Who carries a shield of American flag theme in Avengers?",
            "answer" : "Captain America"
        },
        4 : {
            "question" : "Which avenger is green in color?",
            "answer" : "Hulk"
        },
        5 : {
            "question" : "Which avenger can change it's size?",
            "answer" : "AntMan"
        },
        6 : {
            "question" : "Which Avenger is red in color and has mind stone?",
            "answer" : "Vision"
        }
    }
    
    7 là dữ liệu hoặc giá trị tương ứng của nó.
    quiz = {
        1 : {
            "question" : "What is the first name of Iron Man?",
            "answer" : "Tony"
        },
        2 : {
            "question" : "Who is called the god of lightning in Avengers?",
            "answer" : "Thor"
        },
        3 : {
            "question" : "Who carries a shield of American flag theme in Avengers?",
            "answer" : "Captain America"
        },
        4 : {
            "question" : "Which avenger is green in color?",
            "answer" : "Hulk"
        },
        5 : {
            "question" : "Which avenger can change it's size?",
            "answer" : "AntMan"
        },
        6 : {
            "question" : "Which Avenger is red in color and has mind stone?",
            "answer" : "Vision"
        }
    }
    
    4
    of the element while individual elements of dictionaries are accessed through
    quiz = {
        1 : {
            "question" : "What is the first name of Iron Man?",
            "answer" : "Tony"
        },
        2 : {
            "question" : "Who is called the god of lightning in Avengers?",
            "answer" : "Thor"
        },
        3 : {
            "question" : "Who carries a shield of American flag theme in Avengers?",
            "answer" : "Captain America"
        },
        4 : {
            "question" : "Which avenger is green in color?",
            "answer" : "Hulk"
        },
        5 : {
            "question" : "Which avenger can change it's size?",
            "answer" : "AntMan"
        },
        6 : {
            "question" : "Which Avenger is red in color and has mind stone?",
            "answer" : "Vision"
        }
    }
    
    5
    pair where
    quiz = {
        1 : {
            "question" : "What is the first name of Iron Man?",
            "answer" : "Tony"
        },
        2 : {
            "question" : "Who is called the god of lightning in Avengers?",
            "answer" : "Thor"
        },
        3 : {
            "question" : "Who carries a shield of American flag theme in Avengers?",
            "answer" : "Captain America"
        },
        4 : {
            "question" : "Which avenger is green in color?",
            "answer" : "Hulk"
        },
        5 : {
            "question" : "Which avenger can change it's size?",
            "answer" : "AntMan"
        },
        6 : {
            "question" : "Which Avenger is red in color and has mind stone?",
            "answer" : "Vision"
        }
    }
    
    6
    is the identifier and
    quiz = {
        1 : {
            "question" : "What is the first name of Iron Man?",
            "answer" : "Tony"
        },
        2 : {
            "question" : "Who is called the god of lightning in Avengers?",
            "answer" : "Thor"
        },
        3 : {
            "question" : "Who carries a shield of American flag theme in Avengers?",
            "answer" : "Captain America"
        },
        4 : {
            "question" : "Which avenger is green in color?",
            "answer" : "Hulk"
        },
        5 : {
            "question" : "Which avenger can change it's size?",
            "answer" : "AntMan"
        },
        6 : {
            "question" : "Which Avenger is red in color and has mind stone?",
            "answer" : "Vision"
        }
    }
    
    7
    is its corresponding data or value.

Bạn phải đảm bảo rằng từ điển của bạn phải ở cùng định dạng như trên hoặc nếu không bạn có thể cần thực hiện các thay đổi cần thiết cho mã để làm cho nó hoạt động cho bạn. Hãy đặt câu hỏi trên tay cầm xã hội của tôi hoặc đăng câu hỏi của bạn dưới đây trong các cuộc thảo luận/nhận xét.Feel free to ask questions on my social handles or post your question below in discussions/comments.

Bây giờ tôi cho rằng bạn có câu hỏi và câu trả lời của bạn sẵn sàng. Đảm bảo rằng tệp Python Q & A của bạn nằm trong cùng một thư mục với tệp Python trò chơi chính của bạn mà chúng tôi sẽ bắt đầu mã hóa chỉ trong một giây.

Bây giờ chúng ta hãy nhảy vào mã hóa.

Mã chúng ta hãy

Điều đầu tiên chúng tôi luôn làm là nhập các mô -đun yêu cầu vào mã của chúng tôi. May mắn cho dự án này, chúng tôi không cần bất kỳ mô -đun cụ thể nào. Tuy nhiên, chúng tôi vẫn cần nhập tệp Python Q & A mà chúng tôi đã tạo trong bước trước.

Chúng tôi đã đặt tên cho tệp Python Q & A của chúng tôi là

quiz = {
    1 : {
        "question" : "What is the first name of Iron Man?",
        "answer" : "Tony"
    },
    2 : {
        "question" : "Who is called the god of lightning in Avengers?",
        "answer" : "Thor"
    },
    3 : {
        "question" : "Who carries a shield of American flag theme in Avengers?",
        "answer" : "Captain America"
    },
    4 : {
        "question" : "Which avenger is green in color?",
        "answer" : "Hulk"
    },
    5 : {
        "question" : "Which avenger can change it's size?",
        "answer" : "AntMan"
    },
    6 : {
        "question" : "Which Avenger is red in color and has mind stone?",
        "answer" : "Vision"
    }
}
8. Đây là cách chúng tôi sẽ nhập nó:
quiz = {
    1 : {
        "question" : "What is the first name of Iron Man?",
        "answer" : "Tony"
    },
    2 : {
        "question" : "Who is called the god of lightning in Avengers?",
        "answer" : "Thor"
    },
    3 : {
        "question" : "Who carries a shield of American flag theme in Avengers?",
        "answer" : "Captain America"
    },
    4 : {
        "question" : "Which avenger is green in color?",
        "answer" : "Hulk"
    },
    5 : {
        "question" : "Which avenger can change it's size?",
        "answer" : "AntMan"
    },
    6 : {
        "question" : "Which Avenger is red in color and has mind stone?",
        "answer" : "Vision"
    }
}
8
. Here's how we will import it:

from questions import quiz

Nhập chế độ FullScreenen EXIT Mode FullScreen

Bạn có thể tìm hiểu thêm về từ điển Python từ đây.

quiz = {
    1 : {
        "question" : "What is the first name of Iron Man?",
        "answer" : "Tony"
    },
    2 : {
        "question" : "Who is called the god of lightning in Avengers?",
        "answer" : "Thor"
    },
    3 : {
        "question" : "Who carries a shield of American flag theme in Avengers?",
        "answer" : "Captain America"
    },
    4 : {
        "question" : "Which avenger is green in color?",
        "answer" : "Hulk"
    },
    5 : {
        "question" : "Which avenger can change it's size?",
        "answer" : "AntMan"
    },
    6 : {
        "question" : "Which Avenger is red in color and has mind stone?",
        "answer" : "Vision"
    }
}
9 dictionary which contains our question & answers from the file
quiz = {
    1 : {
        "question" : "What is the first name of Iron Man?",
        "answer" : "Tony"
    },
    2 : {
        "question" : "Who is called the god of lightning in Avengers?",
        "answer" : "Thor"
    },
    3 : {
        "question" : "Who carries a shield of American flag theme in Avengers?",
        "answer" : "Captain America"
    },
    4 : {
        "question" : "Which avenger is green in color?",
        "answer" : "Hulk"
    },
    5 : {
        "question" : "Which avenger can change it's size?",
        "answer" : "AntMan"
    },
    6 : {
        "question" : "Which Avenger is red in color and has mind stone?",
        "answer" : "Vision"
    }
}
8
.

Chúng tôi sẽ không thể bao gồm nhiều về từ điển trong hướng dẫn này nhưng về cơ bản, đó là một cấu trúc dữ liệu có thể được sử dụng để lưu trữ dữ liệu như một hình thức duy nhất, có tổ chức và dễ truy cập.

Bạn có thể nghĩ về từ điển như danh sách. Nhưng có một số khác biệt chính giữa danh sách & từ điển:

Danh sách được bao quanh trong dấu ngoặc đơn trong khi các từ điển được đặt trong các dấu ngoặc

quiz = {
    1 : {
        "question" : "What is the first name of Iron Man?",
        "answer" : "Tony"
    },
    2 : {
        "question" : "Who is called the god of lightning in Avengers?",
        "answer" : "Thor"
    },
    3 : {
        "question" : "Who carries a shield of American flag theme in Avengers?",
        "answer" : "Captain America"
    },
    4 : {
        "question" : "Which avenger is green in color?",
        "answer" : "Hulk"
    },
    5 : {
        "question" : "Which avenger can change it's size?",
        "answer" : "AntMan"
    },
    6 : {
        "question" : "Which Avenger is red in color and has mind stone?",
        "answer" : "Vision"
    }
}
3.

score = 0

Nhập chế độ FullScreenen EXIT Mode FullScreen

Bạn có thể tìm hiểu thêm về từ điển Python từ đây.

Chúng tôi sẽ không thể bao gồm nhiều về từ điển trong hướng dẫn này nhưng về cơ bản, đó là một cấu trúc dữ liệu có thể được sử dụng để lưu trữ dữ liệu như một hình thức duy nhất, có tổ chức và dễ truy cập.

from questions import quiz
1 loop which will iterate through all the questions.

# Here remember 'quiz' is our dictionary and 'question' is our temp variable
for question in quiz:
    pass

Nhập chế độ FullScreenen EXIT Mode FullScreen

Bạn có thể tìm hiểu thêm về từ điển Python từ đây.

Chúng tôi sẽ không thể bao gồm nhiều về từ điển trong hướng dẫn này nhưng về cơ bản, đó là một cấu trúc dữ liệu có thể được sử dụng để lưu trữ dữ liệu như một hình thức duy nhất, có tổ chức và dễ truy cập.

# Here remember 'quiz' is our dictionary and 'question' is our temp variable
for question in quiz:
    attempts = 3

Nhập chế độ FullScreenen EXIT Mode FullScreen

Bây giờ, chúng ta hãy tạo một vòng lặp

from questions import quiz
2 trong vòng lặp
from questions import quiz
1 của chúng tôi, sẽ chỉ chạy cho đến khi người chơi còn thử.
from questions import quiz
2
loop within our
from questions import quiz
1
loop, which will run only until player has attempts left.

# Here remember 'quiz' is our dictionary and 'question' is our temp variable
for question in quiz:
    attempts = 3
        # this while loop will run until player has more than 0 attempts left
        while attempts > 0:
                pass

Nhập chế độ FullScreenen EXIT Mode FullScreen

Tuyệt quá! Bây giờ chúng ta hãy in các câu hỏi và nhận câu trả lời từ trình phát của chúng tôi. Chúng tôi sẽ sử dụng các chức năng

from questions import quiz
4 &
from questions import quiz
5 cũ của chúng tôi cho điều đó.
from questions import quiz
4
&
from questions import quiz
5
functions for that.

# Here remember 'quiz' is our dictionary and 'question' is our temp variable
for question in quiz:
    attempts = 3
        while attempts > 0: 
                print[quiz[question]['question']] # this will print the current interation of for loop
        answer = input["Enter Answer: "]

Nhập chế độ FullScreenen EXIT Mode FullScreen

Đáng kinh ngạc! Phản hồi của người chơi sẽ được lưu trữ trong biến

from questions import quiz
6.
from questions import quiz
6
variable.

Bây giờ chúng tôi sẽ sử dụng một chức năng sẽ kiểm tra xem câu trả lời được cung cấp bởi người chơi là đúng hay sai. Chúng tôi sẽ đặt tên cho chức năng đó là

from questions import quiz
7. Hiện tại, hãy tập trung vào vòng lặp
from questions import quiz
1 của chúng tôi và sau đó chúng tôi sẽ thấy chức năng này hoạt động như thế nào.
from questions import quiz
7.
For now, let's focus on our
from questions import quiz
1
loop and then we will see how this function works.

# Here remember 'quiz' is our dictionary and 'question' is our temp variable
for question in quiz:
    attempts = 3
        while attempts > 0: 
                print[quiz[question]['question']] # this will print the current interation of for loop
        answer = input["Enter Answer: "]
                check = check_ans[question, answer, attempts, score]

Nhập chế độ FullScreenen EXIT Mode FullScreen

Chúng tôi sẽ chuyển 4 tham số cho chức năng của chúng tôi, đó là:

  • from questions import quiz
    
    9 - Lặp lại hiện tại của vòng lặp
    from questions import quiz
    
    1
    the current iteration of
    from questions import quiz
    
    1
    loop
  • from questions import quiz
    
    6 - Câu trả lời được cung cấp bởi người chơi
    the answer provided by player
  • score = 0
    
    2 [Tùy chọn] - Một tham số tùy chọn về số lần thử còn lại
    an optional parameter of number of attempts left
  • score = 0
    
    3 [Tùy chọn] - Một tham số tùy chọn của điểm số hiện tại của người chơi
    an optional parameter of the current score of the player

Chúng tôi sẽ lưu trữ đầu ra của chức năng của chúng tôi trong biến

score = 0
4.
score = 0
4
variable.

Bây giờ chúng tôi sẽ sử dụng các câu

score = 0
5 để tăng điểm nếu câu trả lời được cung cấp bởi người chơi là đúng.
score = 0
5
statements to increase score if the answer provided by the player is right.

# Here remember 'quiz' is our dictionary and 'question' is our temp variable
for question in quiz:
    attempts = 3
        while attempts > 0: 
                print[quiz[question]['question']] # this will print the current interation of for loop
        answer = input["Enter Answer: "]
                check = check_ans[question, answer, attempts, score]
                if check:
            score += 1
            break
        attempts -= 1

Nhập chế độ FullScreenen EXIT Mode FullScreen

Tại đây, nếu câu trả lời được đưa ra bởi người chơi là đúng thì điểm số sẽ tăng thêm 1 và vòng lặp

from questions import quiz
2 sẽ bị hỏng và vòng lặp
from questions import quiz
1 sẽ chuyển sang câu hỏi tiếp theo.increase by 1 and the
from questions import quiz
2
loop will break and the
from questions import quiz
1
loop will move on to the next question.

Nhưng nếu câu trả lời là sai, thì người chơi sẽ mất một lần thử và trong khi vòng lặp sẽ tiếp tục cho đến khi câu trả lời đúng được cung cấp bởi người chơi hoặc người chơi hết nỗ lực.

Cuối cùng, vòng lặp

from questions import quiz
1 của chúng tôi kết thúc!
from questions import quiz
1
loop ends!

Chúng ta đang quên một cái gì đó? 🤔

Ồ, chúng tôi quên mất việc thực hiện chức năng

from questions import quiz
7 của chúng tôi ... hãy nhanh chóng che đậy điều đó!
from questions import quiz
7
function... Let's cover that quickly!

quiz = {
    1 : {
        "question" : "What is the first name of Iron Man?",
        "answer" : "Tony"
    },
    2 : {
        "question" : "Who is called the god of lightning in Avengers?",
        "answer" : "Thor"
    },
    3 : {
        "question" : "Who carries a shield of American flag theme in Avengers?",
        "answer" : "Captain America"
    },
    4 : {
        "question" : "Which avenger is green in color?",
        "answer" : "Hulk"
    },
    5 : {
        "question" : "Which avenger can change it's size?",
        "answer" : "AntMan"
    },
    6 : {
        "question" : "Which Avenger is red in color and has mind stone?",
        "answer" : "Vision"
    }
}
0

Nhập chế độ FullScreenen EXIT Mode FullScreen

Đây là chức năng của chúng tôi ... hãy phá vỡ nó!

Ở đây một tuyên bố

score = 0
5 sẽ so sánh câu trả lời do người chơi cung cấp với câu trả lời chính xác từ từ điển của chúng tôi.
score = 0
5
statement will compare the answer provided by the player with the correct answer from our dictionary.

Nếu câu trả lời đúng thì nó sẽ trả về

# Here remember 'quiz' is our dictionary and 'question' is our temp variable
for question in quiz:
    pass
1 nếu không nó sẽ trả về
# Here remember 'quiz' is our dictionary and 'question' is our temp variable
for question in quiz:
    pass
2.
# Here remember 'quiz' is our dictionary and 'question' is our temp variable
for question in quiz:
    pass
1
or else it will return
# Here remember 'quiz' is our dictionary and 'question' is our temp variable
for question in quiz:
    pass
2
.

Hãy thêm một vài câu lệnh in để thông báo cho người chơi nếu câu trả lời của anh ta đúng hay sai.

quiz = {
    1 : {
        "question" : "What is the first name of Iron Man?",
        "answer" : "Tony"
    },
    2 : {
        "question" : "Who is called the god of lightning in Avengers?",
        "answer" : "Thor"
    },
    3 : {
        "question" : "Who carries a shield of American flag theme in Avengers?",
        "answer" : "Captain America"
    },
    4 : {
        "question" : "Which avenger is green in color?",
        "answer" : "Hulk"
    },
    5 : {
        "question" : "Which avenger can change it's size?",
        "answer" : "AntMan"
    },
    6 : {
        "question" : "Which Avenger is red in color and has mind stone?",
        "answer" : "Vision"
    }
}
1

Nhập chế độ FullScreenen EXIT Mode FullScreen

Ở đây có vẻ tốt!

Bạn làm được rồi! Hãy tự hào về bản thân 🤩

Một số ý tưởng để thử

Dưới đây là một số ý tưởng nhanh chóng bạn có thể thử với dự án này.

  • Làm cho nó nhiều người chơi - hãy thử sửa đổi trò chơi này để nhiều hơn một người chơi có thể thưởng thức trò chơi này cùng một lúc. Bạn có thể làm điều này bằng cách chỉ cần thêm một vòng lặp
    from questions import quiz
    
    1 bổ sung sẽ chứa tên của người chơi và điểm số của mỗi người chơi được lưu trữ riêng. Người chơi có điểm số cao nhất sẽ giành chiến thắng trong trò chơi.
    Try modifying this game so that more than one player can enjoy this game at once. You can do this by simply adding an additional
    from questions import quiz
    
    1
    loop which will contain the names of the players and score of each player is stored separately. The player with the highest score will win the game.
  • Sử dụng định dạng MCQ - Không chỉ là bài kiểm tra, bạn cũng có thể sử dụng nó tiến hành các bài kiểm tra MCQ. Tất cả những gì bạn phải làm là sửa đổi chức năng in để in nhiều câu trả lời và người chơi sẽ phải đoán câu trả lời đúng. Not just quiz, you can also use it conduct MCQ tests. All you have to do is modify the print function to print the multiple answers and the player will have to guess the right answer.
  • Sử dụng API - Sử dụng API thú vị để tự động tìm nạp các câu hỏi từ web để bạn không phải gặp rắc rối khi tự tạo câu hỏi và câu trả lời. Một trong những yêu thích của tôi là API siêu anh hùng. Make use of an interesting API to automatically fetch questions from the web so you don't have to get into the hassle of creating the questions and answers on your own. One of my favorite is the Superhero API.

Mã nguồn

Bạn có thể tìm thấy mã nguồn đầy đủ của dự án này ở đây -

mindninjaX/Python-Projects-for-Beginners

Ủng hộ

Cảm ơn bạn rất nhiều vì đã đọc! Tôi hy vọng bạn thấy dự án mới bắt đầu này hữu ích.

Nếu bạn thích công việc của tôi, vui lòng xem xét việc mua cho tôi một ly cà phê để tôi có thể mang nhiều dự án hơn, nhiều bài viết hơn cho bạn.

Ngoài ra, nếu bạn có bất kỳ câu hỏi hoặc nghi ngờ nào, hãy liên hệ với tôi trên Twitter, LinkedIn & GitHub. Hoặc bạn cũng có thể đăng một bình luận/thảo luận và tôi sẽ cố gắng hết sức để giúp bạn: D

Làm thế nào để bạn thực hiện một bài kiểm tra từng bước?

Một bước đi từng bước:..
Xác định loại bài kiểm tra ..
Chọn các loại câu hỏi câu hỏi ..
Đặt câu hỏi hay ..
Làm việc ra các tùy chọn trả lời ..
Quyết định về các thuộc tính đố ..
Thêm giọng nói và câu hỏi thiết kế ..

Làm thế nào để bạn tạo một câu hỏi và câu trả lời trong Python?

Làm thế nào để bạn hỏi một câu hỏi trong Python ?..
Câu hỏi = đầu vào ["câu hỏi của bạn"].
Nếu câu hỏi == ["Có"].
In ["Làm tốt"].
Elif câu hỏi == ["Không"].
in ["thử lại"].

Làm cách nào để tạo một trò chơi trong Python?

Dưới đây là ví dụ sau đây về việc tạo một cửa sổ pygame đơn giản ...
Nhập pygame ..
pygame.init[].
màn hình = pygame.display.set_mode [[400.500]].
Xong = Sai ..
trong khi không được thực hiện:.
cho sự kiện trong pygame.event.get []:.
Nếu event.type == pygame.quit:.
Xong = Đúng ..

Làm thế nào để tôi thực hiện một bài kiểm tra tính cách trong Python?

Xây dựng ứng dụng..
Tạo một tệp Python.....
Nhập hệ thống mô -đun Python.....
Một chức năng hiển thị bản sắc tính cách.....
Một chức năng tính toán bài kiểm tra tính cách.....
Chức năng chạy.....
Xử lý ngoại lệ.....
Thoát khỏi ứng dụng với chức năng thoát.....
Chức năng trang chủ ..

Bài Viết Liên Quan

Chủ Đề