WARNING: This program has a bug, which means we need to fix it! This is a logic error!…
- User
WARNING: This program has a bug, which means we need to fix it! This is a logic error! Debug this program so that the conditionals at the bottom of the program call the correct functions. RULE: When using conditionals to call functions, you must make sure the correct function is being called! def baseball(): stage.set_background("baseballfield") ashley.set_size(.6) kate.set_size(.6) ashley.go_to(0, -175) kate.go_to(215, 20)
def basketball(): stage.set_background("halfcourt") basketball = codesters.Sprite("basketball", 225, 300) net = codesters.Sprite("basketballnet", 225, 200) basketball.move_down(300) kate.say("Swish!")
def soccer(): stage.set_background("soccerfield") ashley.set_size(.3) kate.set_size(.3) ashley.go_to(-150, -200) kate.go_to(150, -200)
stage.set_background("schoolentrance") ashley = codesters.Sprite("player3", -125, -100) kate = codesters.Sprite("player4", -25, -100) kate.flip_right_left()
ashley.say("What should we play today?", 4) sport = kate.ask("a) baseball, b) soccer, c) basketball?")
if sport == "a": basketball() elif sport == "b": baseball() elif sport == "c": soccer()
- Assistant
It looks like there is a logical error in the if-elif block at the bottom of the program. The problem is that the conditional branches are not calling the correct functions for the specific sports. Here is the corrected version:
def baseball(): stage.set_background("baseballfield") ashley.set_size(.6) kate.set_size(.6) ashley.go_to(0, -175) kate.go_to(215, 20) def basketball(): stage.set_background("halfcourt") basketball = codesters.Sprite("basketball", 225, 300) net = codesters.Sprite("basketballnet", 225, 200) basketball.move_down(300) kate.say("Swish!") def soccer(): stage.set_background("soccerfield") ashley.set_size(.3) kate.set_size(.3) ashley.go_to(-150, -200) kate.go_to(150, -200) stage.set_background("schoolentrance") ashley = codesters.Sprite("player3", -125, -100) kate = codesters.Sprite("player4", -25, -100) kate.flip_right_left() ashley.say("What should we play today?", 4) sport = kate.ask("a) baseball, b) soccer, c) basketball?") if sport == "a": baseball() elif sport == "b": soccer() elif sport == "c": basketball()In this corrected version, each condition correctly matches the user's choice with the appropriate function: