Nov-02-2018, 04:17 PM
(This post was last modified: Nov-02-2018, 04:17 PM by itmustbebunnies.)
Hi guys! I am taking my first computer programming class and working on a homework assignment involving a game that will change a smiley face (drawn using turtle) based on user input.
Basically, when the program starts a regular smiley face will be drawn (yellow face, black eyes and mouth, smile). The user is then prompted to change the face with the following menu:
Change My Face
1) Make me frown
2) Make me angry
3) Make my eyes blue
0) Quit
If the user selects 1, the smiley face is redrawn with the frown turned to a smile and the menu will change to:
Change My Face
1) Make me smile
2) Make me angry
3) Make my eyes blue
0) Quit
If the user selects 2, the smiley face is redrawn and filled in red with a frown and the menu will change to:
Change My Face
1) Make me smile
2) Make me happy
3) Make my eyes blue
0) Quit
And so on, with the menu always changing based on the attributes of the face that was last drawn.
We were given starter code to work on this project (with __<Fill-In>__ everywhere we are to add a single line/partial line of code). We also need to and can add methods and data as necessary to this existing code. I am having a hard time understanding class and objects, anyway, and this is proving to be a more difficult assignment for me than I originally thought it would be. Here is the starter code we were given (we are defining class in the same file as our main function for convenience):
Basically, when the program starts a regular smiley face will be drawn (yellow face, black eyes and mouth, smile). The user is then prompted to change the face with the following menu:
Change My Face
1) Make me frown
2) Make me angry
3) Make my eyes blue
0) Quit
If the user selects 1, the smiley face is redrawn with the frown turned to a smile and the menu will change to:
Change My Face
1) Make me smile
2) Make me angry
3) Make my eyes blue
0) Quit
If the user selects 2, the smiley face is redrawn and filled in red with a frown and the menu will change to:
Change My Face
1) Make me smile
2) Make me happy
3) Make my eyes blue
0) Quit
And so on, with the menu always changing based on the attributes of the face that was last drawn.
We were given starter code to work on this project (with __<Fill-In>__ everywhere we are to add a single line/partial line of code). We also need to and can add methods and data as necessary to this existing code. I am having a hard time understanding class and objects, anyway, and this is proving to be a more difficult assignment for me than I originally thought it would be. Here is the starter code we were given (we are defining class in the same file as our main function for convenience):
import turtle class Face: def __init__(self): self.__smile = True self.__happy = True self.__dark_eyes = True def draw_face(self): turtle.clear() self.__draw_head() self.__draw_eyes() self.__draw_mouth() def is_smile(self): ___<Fill-In>___ def is_happy(self): ___<Fill-In>___ def is_dark_eyes(self): ___<Fill-In>___ def change_mouth(self): ___<Fill-In>___ self.draw_face() def change_emotion(self): ___<Fill-In>___ self.draw_face() def change_eyes(self): ___<Fill-In>___ self.draw_face() def main(): face = ___<Fill-In>___ face.___<Fill-In>___ done = False while not done: print("Change My Face") mouth = "frown" ____<Fill-In>___ "smile" emotion = "angry" ____<Fill-In>___ "happy" eyes = "blue" ____<Fill-In>___ "black" print("1) Make me", mouth) print("2) Make me", emotion) print("3) Make my eyes", eyes) print("0) Quit") menu = eval(input("Enter a selection: ")) if menu == 1: ___<Fill-In>___ elif menu == 2: ___<Fill-In>___ elif menu == 3: ___<Fill-In>___ else: break print("Thanks for Playing") turtle.hideturtle() turtle.done() main()First, I am confused by the menu:
mouth = "frown" ____<Fill-In>___ "smile" emotion = "angry" ____<Fill-In>___ "happy" eyes = "blue" ____<Fill-In>___ "black"I was thinking of setting a variable in my code to draw the face (like eye_color) and using if statements:
if eye_color == "blue": eyes = "black" else: eyes = "blue"is there a simpler way to achieve this? The way it is set up looks like I should be doing it with a partial line of code...