screen = turtle.Screen() screen.title("Trivia Turtle Race") screen.bgcolor("white") finish_line = turtle.Turtle() finish_line.speed(0) finish_line.color("black") p1, p2, p3 = create_players() players = [p1, p2, p3] questions = [     Question("What is the largest mammal?", {1: "Whale", 2: "Lion", 3: "Orca", 4: "Wolf"}, 1),     Question("What is the name of the planet that is closest to the sun?", {1: "Jupiter", 2: "Mars", 3: "Mercury", 4: "Saturn"}, 3),     Question("What is the capital of the United States?", {1: "Washington D.C.", 2: "Philadelphia", 3: "New York", 4: "Texas"}, 1),     Question("What is 28 divided by 7?", {1: "6", 2: "7", 3: "2", 4: "4"}, 4),     Question("How many inches are in 1 foot?", {1: "6", 2: "12", 3: "10", 4: "5"}, 2),     Question("Who discovered the laws of gravity?", {1: "Isaac Newton", 2: "Albert Einstein", 3: "Galileo", 4: "Charles Darwin"}, 1),     Question("How many teeth does an adult have?", {1: "24", 2: "45", 3: "32", 4: "39"}, 3),     Question("When do we celebrate Independence Day?", {1: "September 18", 2: "December 25", 3: "June 18", 4: "July 4"}, 4),     Question("Which ocean is located on the west coast of North America?", {1: "Atlantic Ocean", 2: "Pacific Ocean", 3: "Arctic Ocean", 4: "Indian Ocean"}, 2),     Question("Who was the second president of the United States?", {1: "George Washington", 2: "John Adams", 3: "Thomas Jefferson", 4: "Abraham Lincoln"}, 2),     Question("What is the 3rd planet from the sun?", {1: "Mercury", 2: "Pluto", 3: "Earth", 4: "Moon"}, 3),     Question("What do you call a baby cow?", {1: "Calf", 2: "Cub", 3: "Joey", 4: "Puppy"}, 1),     Question("How many legs does a spider have?", {1: "4", 2: "7", 3: "5", 4: "8"}, 4),     Question("How many stripes are on the American Flag?", {1: "10", 2: "13", 3: "15", 4: "17"}, 2),     Question("How many planets are in our solar system?", {1: "4", 2: "6", 3: "8", 4: "10"}, 3),     Question("Where is the leaning tower of Piza?", {1: "Italy", 2: "Paris", 3: "Argentina", 4: "Greece"}, 1),     Question("How many days are in a year?", {1: "286", 2: "312", 3: "345", 4: "365"}, 4),     Question("How many colors are in a rainbow?", {1: "4", 2: "7", 3: "8", 4: "10"}, 2),     Question("What is the largest state in the United States?", {1: "Texas", 2: "Florida", 3: "Alaska", 4: "California"}, 3),     Question("What is the largest continent?", {1: "Asia", 2: "Europe", 3: "North America", 4: "Australia"}, 1),     Question("Who became the 50th US state?", {1: "Alaska", 2: "Hawaii", 3: "Wyoming", 4: "North Dakota"}, 2),     Question("How much is a half dozen?", {1: "4", 2: "5", 3: "7", 4: "6"}, 4),     Question("How many quarts in a gallon?", {1: "4", 2: "5", 3: "3", 4: "8"}, 1),     Question("How many dimes make a dollar?", {1: "5", 2: "7", 3: "10", 4: "12"}, 3),     Question("What is the smallest state in the US?", {1: "Delaware", 2: "New Jersey", 3: "Utah", 4: "Rhode Island"}, 4),      ]

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

screen = turtle.Screen()
screen.title("Trivia Turtle Race")
screen.bgcolor("white")


finish_line = turtle.Turtle()
finish_line.speed(0)
finish_line.color("black")


p1, p2, p3 = create_players()
players = [p1, p2, p3]


questions = [
    Question("What is the largest mammal?", {1: "Whale", 2: "Lion", 3: "Orca", 4: "Wolf"}, 1),
    Question("What is the name of the planet that is closest to the sun?", {1: "Jupiter", 2: "Mars", 3: "Mercury", 4: "Saturn"}, 3),
    Question("What is the capital of the United States?", {1: "Washington D.C.", 2: "Philadelphia", 3: "New York", 4: "Texas"}, 1),
    Question("What is 28 divided by 7?", {1: "6", 2: "7", 3: "2", 4: "4"}, 4),
    Question("How many inches are in 1 foot?", {1: "6", 2: "12", 3: "10", 4: "5"}, 2),
    Question("Who discovered the laws of gravity?", {1: "Isaac Newton", 2: "Albert Einstein", 3: "Galileo", 4: "Charles Darwin"}, 1),
    Question("How many teeth does an adult have?", {1: "24", 2: "45", 3: "32", 4: "39"}, 3),
    Question("When do we celebrate Independence Day?", {1: "September 18", 2: "December 25", 3: "June 18", 4: "July 4"}, 4),
    Question("Which ocean is located on the west coast of North America?", {1: "Atlantic Ocean", 2: "Pacific Ocean", 3: "Arctic Ocean", 4: "Indian Ocean"}, 2),
    Question("Who was the second president of the United States?", {1: "George Washington", 2: "John Adams", 3: "Thomas Jefferson", 4: "Abraham Lincoln"}, 2),
    Question("What is the 3rd planet from the sun?", {1: "Mercury", 2: "Pluto", 3: "Earth", 4: "Moon"}, 3),
    Question("What do you call a baby cow?", {1: "Calf", 2: "Cub", 3: "Joey", 4: "Puppy"}, 1),
    Question("How many legs does a spider have?", {1: "4", 2: "7", 3: "5", 4: "8"}, 4),
    Question("How many stripes are on the American Flag?", {1: "10", 2: "13", 3: "15", 4: "17"}, 2),
    Question("How many planets are in our solar system?", {1: "4", 2: "6", 3: "8", 4: "10"}, 3),
    Question("Where is the leaning tower of Piza?", {1: "Italy", 2: "Paris", 3: "Argentina", 4: "Greece"}, 1),
    Question("How many days are in a year?", {1: "286", 2: "312", 3: "345", 4: "365"}, 4),
    Question("How many colors are in a rainbow?", {1: "4", 2: "7", 3: "8", 4: "10"}, 2),
    Question("What is the largest state in the United States?", {1: "Texas", 2: "Florida", 3: "Alaska", 4: "California"}, 3),
    Question("What is the largest continent?", {1: "Asia", 2: "Europe", 3: "North America", 4: "Australia"}, 1),
    Question("Who became the 50th US state?", {1: "Alaska", 2: "Hawaii", 3: "Wyoming", 4: "North Dakota"}, 2),
    Question("How much is a half dozen?", {1: "4", 2: "5", 3: "7", 4: "6"}, 4),
    Question("How many quarts in a gallon?", {1: "4", 2: "5", 3: "3", 4: "8"}, 1),
    Question("How many dimes make a dollar?", {1: "5", 2: "7", 3: "10", 4: "12"}, 3),
    Question("What is the smallest state in the US?", {1: "Delaware", 2: "New Jersey", 3: "Utah", 4: "Rhode Island"}, 4),
    
]


play_game()


turtle.done()

The code given is the last of the code in the attached images. I am having trouble with repeating questions and making the players start on the left side of the screen.

game5.py - C:\Users\lilxa\game5.py (3.11.3)
File Edit Format Run Options Window Help
def clear players ():
for player in players:
player.clear()
def reset_players ():
for player in players:
player.penup ()
player.goto (-200, player.ycor ())
player. pendown ()
def play_game ():
draw_finish_line ().
player_positions = {1: -200, 2: -200, 3: -200)
player_scores = {1:0, 2: 0, 3: 0}
questions_per_player = 2
distance to finish = 400
while True:
for current_player in range (1, 4):
if player_scores [current_player] >= distance_to_finish:
print (f"Player (current_player) won the game!")
return
question = random. choice (questions)
if current_player == 1:
if ask question (current_player, question):
player_scores [current_player] += 50
elif current_player == 2:
if ask question (current_player, question) :
player_scores [current_player] += 50
elif current_player == 3:
if ask question (current_player, question):
player_scores [current_player] + 50
clear players ()
for player in players:
if player == pl:
player.goto (player_positions [1] + player_scores [1], player.ycor ())
player.stamp ()
elif player == p2:
player. goto (player_positions [2] + player_scores [2], player.ycor ())
player.stamp ()
elif player === p3:
player.goto (player_positions [3] + player_scores [3], player.ycor ())
player.stamp ()
print ("No player crossed the finish line. It's a draw!")
reset_players ()
play_again = input ("Do you want to play again? (yes/no): ")
if play_again.lower () == "yes":
clear_players ()
play_game ()
I
x
Transcribed Image Text:game5.py - C:\Users\lilxa\game5.py (3.11.3) File Edit Format Run Options Window Help def clear players (): for player in players: player.clear() def reset_players (): for player in players: player.penup () player.goto (-200, player.ycor ()) player. pendown () def play_game (): draw_finish_line (). player_positions = {1: -200, 2: -200, 3: -200) player_scores = {1:0, 2: 0, 3: 0} questions_per_player = 2 distance to finish = 400 while True: for current_player in range (1, 4): if player_scores [current_player] >= distance_to_finish: print (f"Player (current_player) won the game!") return question = random. choice (questions) if current_player == 1: if ask question (current_player, question): player_scores [current_player] += 50 elif current_player == 2: if ask question (current_player, question) : player_scores [current_player] += 50 elif current_player == 3: if ask question (current_player, question): player_scores [current_player] + 50 clear players () for player in players: if player == pl: player.goto (player_positions [1] + player_scores [1], player.ycor ()) player.stamp () elif player == p2: player. goto (player_positions [2] + player_scores [2], player.ycor ()) player.stamp () elif player === p3: player.goto (player_positions [3] + player_scores [3], player.ycor ()) player.stamp () print ("No player crossed the finish line. It's a draw!") reset_players () play_again = input ("Do you want to play again? (yes/no): ") if play_again.lower () == "yes": clear_players () play_game () I x
game5.py-C:\Users\lilxa\game5.py (3.11.3)
File Edit Format Run Options Window Help
import random
import turtle
class Question:
definit
_init_ (self, ques, answers, corrAns) :
self.question = ques
self.answers answers
self.correctAns = corrAns
def getQuestion (self):
question_str= self.question + "\n"
for num, answer in self.answers.items ():
question_str + str (num) + ":" + answer + "\n"
return question_str
def getCorrectAns (self):
return self.correctAns
def draw_finish_line ():
finish line.penup ()
finish line.goto (200, -200)
finish line.pendown ()
finish line.left (90)
finish line. forward (400)
finish line.penup ()
def create_players ():
pl= turtle. Turtle()
pl.shape("turtle").
pl.color ("red")
pl.penup ()
pl. goto (-200, -160)
pl.pendown()
p2 = turtle. Turtle()
p2.shape ("circle")
p2.color ("blue")
p2.penup ()
p2.goto (-200, -120)
p2.pendown ()
=
p3 turtle. Turtle ()
p3.shape ("square")
p3.color ("green")
p3.penup ()
p3. goto (-200, -80)
p3.pendown ()
return pl, p2, p3
def ask question (player, question):
print (f"Player (player} Chance")
print (question.getQuestion())
user_ans input ("Enter your answer: ")
if question.getCorrectAns () == int (user_ans) :
print("Your Answer is Correct")
return True
else:
print ("Your Answer is Incorrect. The correct answer is", question.getCorrectAns ())
I
0
X
Ln: 18 Col: 0
Transcribed Image Text:game5.py-C:\Users\lilxa\game5.py (3.11.3) File Edit Format Run Options Window Help import random import turtle class Question: definit _init_ (self, ques, answers, corrAns) : self.question = ques self.answers answers self.correctAns = corrAns def getQuestion (self): question_str= self.question + "\n" for num, answer in self.answers.items (): question_str + str (num) + ":" + answer + "\n" return question_str def getCorrectAns (self): return self.correctAns def draw_finish_line (): finish line.penup () finish line.goto (200, -200) finish line.pendown () finish line.left (90) finish line. forward (400) finish line.penup () def create_players (): pl= turtle. Turtle() pl.shape("turtle"). pl.color ("red") pl.penup () pl. goto (-200, -160) pl.pendown() p2 = turtle. Turtle() p2.shape ("circle") p2.color ("blue") p2.penup () p2.goto (-200, -120) p2.pendown () = p3 turtle. Turtle () p3.shape ("square") p3.color ("green") p3.penup () p3. goto (-200, -80) p3.pendown () return pl, p2, p3 def ask question (player, question): print (f"Player (player} Chance") print (question.getQuestion()) user_ans input ("Enter your answer: ") if question.getCorrectAns () == int (user_ans) : print("Your Answer is Correct") return True else: print ("Your Answer is Incorrect. The correct answer is", question.getCorrectAns ()) I 0 X Ln: 18 Col: 0
Expert Solution
steps

Step by step

Solved in 5 steps with 18 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education