Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Translate this into Python #include <iostream> #include <fstream> using namespac

ID: 3577071 • Letter: T

Question

Translate this into Python

#include <iostream>
#include <fstream>

using namespace std;

class MathZombie {
public:
   int left;
   int right;

   MathZombie(int a, int b) {
       left = a;
       right = b;
   }

   int add() {
       return left + right;
   }

   int multiply() {
       return left * right;
   }

   int isEven() {
       if (left % 2 == 0 && right % 2 == 0) {
           return true;
       } else {
           return false;
       }
   }

   void drawWinningPattern() {
       for (int i = 1; i < 5; i++) {
           for (int j = 1; j < i; j++) {
               cout << "###########";
           }
           cout << "^^^^^^" << endl;
       }
   }

   void drawLoserPattern() {
       for (int i = 1; i < 3; i++) {
           for (int j = 1; j < i; j++) {
               cout << "~~~~~~~~~";
           }
           cout << "{}{}{}{}" << endl;
       }
   }

};
//class for the strory to continue after you exit the barn; this is the user class
class User {
public:
   char username[50];

   User(char name[50])
   {
       string(username, name);
   }

   void encounterBigZombie() {
       cout << "'you exit the barn and walk 1 mile out when suddenly...'"
               << endl;
       cout << "BIG MATH ZOMBIE!!" << endl;
       cout
               << "'you can't run, the big math zombie is blocking your path, You MUST FIGHT!'"
               << endl;
       cout << "You would need to any two integers. Enter first integer now: "
               << endl;
       int left, right;
       cin >> left;
       cout << "Enter second integer: " << endl;
       cin >> right;

       int result;
       MathZombie bigZombie(left, right);
       cout << "In order to kill zombie give correct answer. What is: " << left
               << " * " << right << ": " << endl;
       cin >> result;

       if (result == bigZombie.multiply()) {
           cout << "Good job. You won!" << endl;
           bigZombie.drawWinningPattern();
       } else {
           cout << "Wrong!!!! The correct answer is: " << bigZombie.multiply()
                   << endl;
           cout << "You lost." << endl;
           bigZombie.drawLoserPattern();
       }
   }

   int choiceOnePath() {
       int choiceOnePath;
       cout
               << "You and your friend, Steven, are camping at a deserted barn. What would you like to do?"
               << endl;
       cout << "Enter '1' to talk your friend, Steven?" << endl;
       cout << "Enter '2' to exit the barn?" << endl;

       cout << " Enter your choice: ";
       cin >> choiceOnePath;
       while (choiceOnePath != 1 && choiceOnePath != 2 && choiceOnePath != 420) {
           cout << "That's Not an Option! Press either '1' or '2'." << endl;
           cin >> choiceOnePath;
       }
//diaglogue to the game
       if (choiceOnePath == 1) {
           cout
                   << " !!!----------------------Chapter One: Escape----------------------!!!"
                   << endl;
           cout << " You: Hey Steven, how's your broken leg healing up?"
                   << endl;
           cout
                   << "Steven: Not so good. I need you to go and get me pain medication from the CVC 3 miles down, can you do that for me?"
                   << endl;
           cout << "You: Sure man, I'll try to be back before dark." << endl;
           cout
                   << "'you exit the barn with a pocket knife, a gun with 3 bullets, and your watch"
                   << endl;
//dialogue to path choice 2 of trhe game
       } else if (choiceOnePath == 2) {
           cout
                   << " !!!----------------------Chapter One: Escape----------------------!!!"
                   << endl;
           cout
                   << " You: Steven Im going out for a bit, do you need anything?"
                   << endl;
           cout
                   << "Steven: Ya, if you can get me some meds to ease up the pain for my broken leg..."
                   << endl;
           cout
                   << "You: Sure man, I'll try to be back before dark with those meds, see you soon."
                   << endl;
           cout
                   << "'you exit the barn with a pocket knife, a gun with 3 bullets, and your watch"
                   << endl;
       } else if (choiceOnePath == 420) {
           cout << "Cheat code activated. You won the game my friend!!"//cheat code to win the game
                   << endl;
           MathZombie fakeZombie(0, 0);
           fakeZombie.drawWinningPattern();
       }

       return choiceOnePath;
   }

   void writeToFile(char name[]) {
       // open a file in write mode.
       ofstream outfile;
       outfile.open("sasha.txt");

       cout << "Writing to the file: " << endl << name << endl;

       // write name into the file.
       outfile << name << endl;

       // close the opened file.
       outfile.close();
   }

   void readFromFile() {
       char data[50];

       // open a file in read mode.
       ifstream infile;
       infile.open("sasha.txt");

       cout << "Data read from file:" << endl;
       infile >> data;

       // write the data at the screen.
       cout << data << endl;

       // close the opened file.
       infile.close();
   }
};

int main() {
   char name[50];

   cout
           << "You are one of the few to survive a zombie apocolyps, what is your name?"
           << endl;
   cin.getline(name, 50);

   User user(name);

   user.writeToFile(name);
   user.readFromFile();

   int choiceOnePath = user.choiceOnePath(); //function to call path choice
//couts the pathchoice depending on which one you puck
   if (choiceOnePath == 1) {
       cout << "***********************************************" << endl;
       cout << "Bad choice. Something bad is about to happen." << endl;
       user.encounterBigZombie(); //uses the user class to continue the story
   } else if (choiceOnePath == 2) {
       cout << "***********************************************" << endl;
       cout
               << "Good choice. All you have to do now is to enter to even numbers. If you make a mistake you will lose"
               << endl;
       cout << "Enter first number:" << endl; //entering the first number
       int a, b;
       cin >> a;
       cout << "Enter second number:" << endl; //entering the second number
       cin >> b;
       MathZombie smallZombie(a, b); //uses mathzombie class to input both numbers and ask you to multiply them
       if (smallZombie.isEven()) {
           cout << "Correct answer. You won!" << endl; //depending if you won the game or lost the game it couts
           smallZombie.drawWinningPattern();
       } else {
           cout << "You are so dumb! You lost. :(" << endl;
           smallZombie.drawLoserPattern();
       }
   }
}

Explanation / Answer

class MathZombie:
    left = 0
    right = 0

    def __init__(self, a, b):
        self.left = a
        self.right = b

    def add(self):
        return self.left + self.right

    def multiply(self):
        return self.left * self.right

    def isEven(self):
        if (self.left % 2 == 0 and self.right % 2 == 0):
            return True
        else:
            return False

    def drawWinningPattern(self):
        for i in range(4):
            for j in range(1, i):
                print "###########",
            print "^^^^^^"

    def drawLoserPattern(self):
        for i in range(2):
            for j in range(1,i):
                print "~~~~~~~~~",
            print "{}{}{}{}"

#class for the strory to continue after you exit the barn; this is the user class
class User:
    username = ''
    def __init__(self, name):
        username = name

    def encounterBigZombie(self):
        print "'you exit the barn and walk 1 mile out when suddenly...'"
        print "BIG MATH ZOMBIE!!"
        print "'you can't run, the big math zombie is blocking your path, You MUST FIGHT!'"
        print "You would need to any two integers. Enter first integer now: "
        left = input()
        right = input("Enter second integer: ")
        bigZombie = MathZombie(left, right)
        result = input("In order to kill zombie give correct answer. What is: "+str(left)+" * "+str(right)+": ")
        if (result == bigZombie.multiply()):
            print "Good job. You won!"
            bigZombie.drawWinningPattern()
        else:
            print "Wrong!!!! The correct answer is: " + str(bigZombie.multiply())
            print "You lost."
            bigZombie.drawLoserPattern()

    def choiceOnePath(self):
        print "You and your friend, Steven, are camping at a deserted barn. What would you like to do?"
        print "Enter '1' to talk your friend, Steven?"
        print "Enter '2' to exit the barn?"
        choiceOnePath = input("Enter your choice: ")
        while (choiceOnePath != 1 and choiceOnePath != 2 and choiceOnePath != 420):
            choiceOnePath = input("That's Not an Option! Press either '1' or '2'.")

        if (choiceOnePath == 1):
            print " !!!----------------------Chapter One: Escape----------------------!!!"
            print " You: Hey Steven, how's your broken leg healing up?"
            print "Steven: Not so good. I need you to go and get me pain medication from the CVC 3 miles down, can you do that for me?"
            print "You: Sure man, I'll try to be back before dark."
            print "'you exit the barn with a pocket knife, a gun with 3 bullets, and your watch"
        elif (choiceOnePath == 2):
            print " !!!----------------------Chapter One: Escape----------------------!!!"
            print " You: Steven Im going out for a bit, do you need anything?"
            print "Steven: Ya, if you can get me some meds to ease up the pain for my broken leg..."
            print "You: Sure man, I'll try to be back before dark with those meds, see you soon."
            print "'you exit the barn with a pocket knife, a gun with 3 bullets, and your watch"
        elif (choiceOnePath == 420):
            print "Cheat code activated. You won the game my friend!!"
            fakeZombie = MathZombie(0, 0)
            fakeZombie.drawWinningPattern()

        return choiceOnePath

    def writeToFile(self, name):
        f = open("sasha.txt", "w")
        print "Writing to the file: "+ name
        f.write(name)
        f.close()

    def readFromFile(self):
        f = open("sasha.txt", "r")
        print "Data read from file:"
        f.readline()
        f.close()

def main():
    name = raw_input("You are one of the few to survive a zombie apocolyps, what is your name?")
    user = User(name)
    user.writeToFile(name)
    user.readFromFile()

    choiceOnePath = user.choiceOnePath()
    if (choiceOnePath == 1):
        print "***********************************************"
        print "Bad choice. Something bad is about to happen."
        user.encounterBigZombie()
    elif (choiceOnePath == 2):
        print "***********************************************"
        print "Good choice. All you have to do now is to enter to even numbers. If you make a mistake you will lose"
        a = input("Enter first number: ")
        b = input("Enter second number: ")
        smallZombie = MathZombie(a, b)
        if (smallZombie.isEven()):
            print "Correct answer. You won!"
            smallZombie.drawWinningPattern()
        else:
            print "You are so dumb! You lost. :("
            smallZombie.drawLoserPattern()
main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote