Python Forum
Homework: Smiley Face game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework: Smiley Face game
#1
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):

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...
Reply
#2
Well, the code you were given already has that variable (self.__dark_eyes, line 8).

Have you covered condition expressions? Maybe your professor is looking for eyes = "black" if self.__dark_yes else "blue".
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
did you ever finish this assignment? Im running into issues on it, and wondered if you could help me.
Reply
#4
(Jun-08-2019, 01:28 AM)mogy Wrote: did you ever finish this assignment? Im running into issues on it, and wondered if you could help me.

Hi mogy

Please create a new thread, post a minimal code sample (in python code tags) for the specific part your stuck on, explain what you expect to happen and what is actually happening and any errors received in error tags.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Face recognition system with return hostel form safwan 3 553 Jan-30-2024, 03:17 AM
Last Post: safwan
  Homework Hangman Game jagr29 3 2,350 Jan-20-2022, 10:38 PM
Last Post: deanhystad
  Which python built in library is used for face recognition? Michel_John 4 2,000 Sep-28-2021, 07:33 PM
Last Post: Underscore

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020