Last active
August 29, 2015 14:19
-
-
Save mariack/25eb32f0c8130b9044ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
class catDog(): | |
def _init_(self): | |
pass | |
def readFile(self, fn): | |
path = r'C:\Users\tuc31890\Downloads' | |
os.chdir(path) | |
self.fh = open(fn, 'r') | |
self.read = self.fh.readlines() | |
self.fh.close() | |
def askQuestions(self): | |
j = 0 | |
self.catList = [] | |
self.dogList = [] | |
self.neitherList = [] | |
for line in self.read: | |
if j == 0: | |
print('Question:', line) | |
j = 1 | |
else: | |
j = 0 | |
print('Answers: \n') | |
for word in line: | |
a, b, c = line.split(",") | |
print('a.', a) | |
print('b.', b) | |
print('c.', c) | |
print("Your answer:") | |
self.answer = input() | |
while(self.answer.lower() != 'a' and self.answer.lower() != 'b' and self.answer.lower() != 'c'): | |
print("Invalid input. Enter a, b, or c. Try again.") | |
print("Your answer:") | |
self.answer = input() | |
self.acceptInput() | |
def acceptInput(self): | |
if self.answer.strip().lower() == 'a': | |
self.catList.append(self.answer) | |
elif self.answer.strip().lower() == 'b': | |
self.dogList.append(self.answer) | |
elif self.answer.strip().lower() == 'c': | |
self.neitherList.append(self.answer) | |
print("Cat:", self.catList) | |
print("Dog:", self.dogList) | |
print("Neither:", self.neitherList) | |
print("\n") | |
c = catDog() | |
c.readFile('CatDogQuestions.txt') | |
c.askQuestions() | |
print("Cat results:", len(c.catList)) | |
print("Dog results:", len(c.dogList)) | |
print("Neither results:", len(c.neitherList)) | |
if len(c.catList) >= 3: | |
print("You are a cat person.") | |
elif len(c.dogList) >= 3: | |
print("You are a dog person") | |
else: | |
print("You are in the middle.") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
class catdog(): | |
def _init_(self): | |
pass | |
def readfile(self, fn): | |
path = r'C:\Users\tuc31890\Downloads' | |
os.chdir(path) | |
self.fh = open(fn, 'r') | |
self.read = self.fh.readlines() | |
self.fh.close() | |
def askquestions(self): | |
j = 0 | |
self.answerList = [] | |
self.catList = [] | |
self.dogList = [] | |
for line in self.read: | |
if j == 0: | |
print(line) | |
j = 1 | |
else: | |
print('Answers: ', line) | |
answer = input() | |
j = 0 | |
for word in line.split(','): | |
self.answerList.append(word) | |
self.answerList[0] = 'a' | |
self.answerList[1] = 'b' | |
self.answerList[2] = 'c' | |
def acceptInput(self): | |
try: | |
self.answer = input() | |
except: | |
self.acceptInput() | |
if self.answer.lower() not in answerList: | |
print('Try again.') | |
self.acceptInput() | |
c = catdog() | |
c.readfile('CatDogQuestions.txt') | |
c.askquestions() | |
answers = [0,0,0] | |
catCount = 0 | |
dogCount = 0 | |
neitherCount = 0 | |
for r in a: | |
print(r) | |
if dog: | |
dogCount++ | |
elif cat: | |
catCount++ | |
elif neither: | |
neitherCount++ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment