コード例 #1
0
 def test_current_card(self):
     card_1 = Card("What is the capital of Alaska?", "Juneau", "Geography")
     card_2 = Card(
         "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?",
         "Mars", "STEM")
     card_3 = Card(
         "Describe in words the exact direction that is 697.5° clockwise from due north?",
         "North north west", "STEM")
     cards = [card_1, card_2, card_3]
     deck = Deck(cards)
     round = Round(deck)
     self.assertEqual(round.current_card(), card_1)
コード例 #2
0
 def setUp(self):
     self.card_1 = Card("Geography", "What is the capital of Alaska?",
                        "Juneau")
     self.card_2 = Card(
         "STEM",
         "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?",
         "Mars")
     self.card_3 = Card(
         "STEM",
         "Describe in words the exact direction that is 697.5° clockwise from due north?",
         "North north west")
     self.deck = Deck([self.card_1, self.card_2, self.card_3])
     self.round = Round(self.deck)
コード例 #3
0
 def test_percent_correct(self):
     card_1 = Card("What is the capital of Alaska?", "Juneau", "Geography")
     card_2 = Card(
         "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?",
         "Mars", "STEM")
     card_3 = Card(
         "Describe in words the exact direction that is 697.5° clockwise from due north?",
         "North north west", "STEM")
     cards = [card_1, card_2, card_3]
     deck = Deck(cards)
     round = Round(deck)
     round.take_turn("Juneau")
     round.take_turn("Venus")
     round.take_turn("North north west")
     self.assertEqual(round.percent_correct_by_category("Geography"), 100.0)
     self.assertEqual(round.percent_correct_by_category("STEM"), 50.0)
コード例 #4
0
 def test_number_correct(self):
     card_1 = Card("What is the capital of Alaska?", "Juneau", "Geography")
     card_2 = Card(
         "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?",
         "Mars", "STEM")
     card_3 = Card(
         "Describe in words the exact direction that is 697.5° clockwise from due north?",
         "North north west", "STEM")
     cards = [card_1, card_2, card_3]
     deck = Deck(cards)
     round = Round(deck)
     round.take_turn("Juneau")
     round.take_turn("Topeka")
     self.assertEqual(round.number_correct, 1)
     self.assertEqual(len(round.turns), 2)
     self.assertEqual(round.turns[-1].feedback(), "Incorrect")
コード例 #5
0
 def __init__(self, deck):
     self.round = Round(deck)
     self.line_break = "-----------------------------------------------------------------"
     self.total_cards = len(self.round.deck.cards)
コード例 #6
0
class Interface:
    def __init__(self, deck):
        self.round = Round(deck)
        self.line_break = "-----------------------------------------------------------------"
        self.total_cards = len(self.round.deck.cards)

    def welcome(self):
        print(self.line_break)
        print(
            f"|             Welcome! You're playing with {self.total_cards} cards!             |"
        )
        print(self.line_break)
        print(
            f"|                     This is card 1 out of {self.total_cards}.                  |"
        )
        print(self.line_break)
        guess = input(self.round.current_card.question)
        time.sleep(2)
        self.check_answer(guess)

    def check_answer(self, guess):
        print(self.line_break)
        self.round.take_turn(guess)
        time.sleep(1)
        print(self.round.turns[-1].feedback())
        self.next_card()

    def next_card(self):
        if self.round.current_card == 'No More Cards':
            print(self.line_break)
            print(self.round.current_card)
            print("Let's see how you did.......")
            print(self.line_break)
            time.sleep(3)
            self.round_feedback()
        else:
            print(self.line_break)
            total = len(self.round.deck.cards)
            print(
                f"This is card {len(self.round.turns) + 1} out of {self.total_cards}"
            )
            print(self.line_break)
            time.sleep(2)
            guess = input(self.round.current_card.question)
            time.sleep(2)
            self.check_answer(guess)

    def round_feedback(self):
        total = len(self.round.deck.cards)
        print(self.line_break)
        print(
            "|                     ****** Game Stats! *******                  |"
        )
        print(self.line_break)
        print(
            f"You had {self.round.number_correct()} correct guess out of {self.total_cards} for a total score of {self.round.percent_correct()}%."
        )
        self.round_category_feedback()

    def round_category_feedback(self):
        for category in self.round.deck.all_categories():
            print(
                f"{category} - {self.round.percent_correct_by_category(category)}% correct"
            )
        print(self.line_break)
        self.new_game()

    def new_game(self):
        print(self.line_break)
        answer = input("Play another game? Enter y/n: ")
        if answer.lower() == 'n':
            print('Booting Down, Goodbye!')
            time.sleep(3)
        elif answer.lower() == 'y':
            Interface.start()
        else:
            print('Please enter y/n!')
            self.new_game()

    @classmethod
    def start(cls):
        print(
            "|                ****** Generating cards ******                |")
        time.sleep(3)
        cards = CardGenerator.generate_cards()
        deck = Deck(cards)
        interface = Interface(deck)
        interface.welcome()
コード例 #7
0
class Test(unittest.TestCase):
    def setUp(self):
        self.card_1 = Card("Geography", "What is the capital of Alaska?",
                           "Juneau")
        self.card_2 = Card(
            "STEM",
            "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?",
            "Mars")
        self.card_3 = Card(
            "STEM",
            "Describe in words the exact direction that is 697.5° clockwise from due north?",
            "North north west")
        self.deck = Deck([self.card_1, self.card_2, self.card_3])
        self.round = Round(self.deck)

    def test_it_has_attributes(self):
        self.assertEqual(self.round.deck, self.deck)
        expected = "What is the capital of Alaska?"
        self.assertEqual(self.round.deck.cards,
                         [self.card_1, self.card_2, self.card_3])
        self.assertEqual(self.round.deck.cards[0].question, expected)
        self.assertEqual(self.round.turns, [])

    def test_it_has_current_card(self):
        self.assertEqual(self.round.current_card, self.card_1)

    def test_it_can_take_turn(self):
        self.round.take_turn('Juneau')
        new_turn = self.round.turns[0]
        self.assertTrue(new_turn.correct())
        self.assertEqual(new_turn.feedback(), 'Correct')
        self.assertEqual(len(self.round.turns), 1)
        self.assertEqual(self.round.current_card, self.card_2)

        self.round.take_turn('Venus')
        new_turn2 = self.round.turns[1]
        self.assertFalse(new_turn2.correct())
        self.assertEqual(new_turn2.feedback(), 'Incorrect')
        self.assertEqual(len(self.round.turns), 2)
        self.assertEqual(self.round.current_card, self.card_3)

        self.round.take_turn('North north west')
        new_turn3 = self.round.turns[2]
        self.assertTrue(new_turn3.correct())
        self.assertEqual(new_turn3.feedback(), 'Correct')
        self.assertEqual(len(self.round.turns), 3)
        self.assertEqual(self.round.current_card, 'No More Cards')

    def test_it_can_calculate_number_correct(self):
        self.round.take_turn('Juneau')
        self.round.take_turn('Venus')
        self.assertEqual(self.round.number_correct(), 1)

    def test_it_can_calculate_number_correct_by_category(self):
        self.round.take_turn('Ohio')
        self.round.take_turn('Mars')
        self.round.take_turn('North north west')
        self.assertEqual(self.round.number_correct_by_category('STEM'), 2)
        self.assertEqual(self.round.number_correct_by_category('Geography'), 0)

    def test_it_can_calculate_percent_correct(self):
        self.round.take_turn('Ohio')
        self.round.take_turn('Mars')
        self.round.take_turn('North north west')
        self.assertEqual(self.round.percent_correct(), 66.67)

    def test_it_can_calculate_turns_by_category(self):
        self.round.take_turn('Ohio')
        self.round.take_turn('Mars')
        self.round.take_turn('North north west')
        self.assertEqual(self.round.turns_by_category('Geography'), 1)
        self.assertEqual(self.round.turns_by_category('STEM'), 2)

    def test_it_can_calculate_percent_correct_by_category(self):
        self.round.take_turn('Ohio')
        self.round.take_turn('Mars')
        self.round.take_turn('North north west')
        self.assertEqual(self.round.percent_correct_by_category('Geography'),
                         0.00)
        self.assertEqual(self.round.percent_correct_by_category('STEM'),
                         100.00)
コード例 #8
0
from lib.card import Card
from lib.deck import Deck
from lib.round import Round
from lib.turn import Turn
from lib.card_generator import CardGenerator

generator = CardGenerator("cards.txt")
cards = generator.cards
categories = []

deck = Deck(cards)
round = Round(deck)

print(f"Welcome! You're playing with {deck.count} cards.")
print("-------------------------------------")

i = 1
for card in cards:
    if card.category not in categories:
        categories.append(card.category)

    print(f"This is card number {i} out of {deck.count()}")
    print(f"Question: {card.question}")
    guess = input("")
    turn = round.take_turn(guess)
    print(turn.feedback())
    i += 1

print("****** Game over! ******")
print(
    f"You had {round.number_correct} out of {deck.count()} for a total score of {round.percent_correct()}%."
コード例 #9
0
from lib.card import Card
from lib.turn import Turn
from lib.deck import Deck
from lib.round import Round

card_1 = Card("In what state is Greendale Community College?", "colorado", 'Community Trivia')
card_2 = Card("What is the first name of the character that wins Dungeons and Dragons in the first D&D episode?", "pierce", 'Community Trivia')
card_3 = Card("What is the slogan of the STD fair?", "catch knowledge", 'Community Trivia')
card_4 = Card('According to Greek mythology, who was the first woman on Earth?', 'pandora', 'Random Trivia')
card_5 = Card('Two US States dont recognize daylight savings. Hawaii is one. What is the other?', 'arizona', 'Random Trivia')
card_6 = Card('The ____ is the loudest animal on Earth.', 'sperm whale', 'Random Trivia')

cards = [card_1, card_2, card_3, card_4, card_5, card_6]
deck = Deck(cards)
round = Round(deck)
total_cards = len(cards)
categories = deck.all_categories()

intro = "Welcome to Flashcards! You are playing with %s cards" % total_cards
print(intro)

while len(cards) > 0:
  print('*-*-*-*-*-*-*-*-*-*-*-*-*-*-*')
  print('This is card number %s out of %s' % (total_cards - len(cards) + 1, total_cards))
  print('Question: %s' % round.current_card().question)

  guess = input('>>').lower()
  
  guess = round.take_turn(guess)
  answer = guess.card.answer
コード例 #10
0
    def test_round(self):
        card_1 = Card("What is the capital of Alaska?", "Juneau", 'Geography')
        card_2 = Card("What is the square root of 169?", "13", 'STEM')
        card_3 = Card("What is the power house of the freaking cell?",
                      "Mitochondria", 'STEM')

        cards = [card_1, card_2, card_3]

        deck = Deck(cards)

        round = Round(deck)

        assert round.deck == deck

        assert round.turns == []

        assert round.current_card() == card_1

        new_turn = round.take_turn('Juneau')

        assert isinstance(new_turn, Turn)

        assert new_turn.correct() == True

        assert round.turns == [new_turn]

        assert round.number_correct() == 1

        assert round.current_card() == card_2

        newer_turn = round.take_turn('12')

        assert len(round.turns) == 2
        assert (round.total_turns()) == 2

        assert newer_turn.correct() == False

        assert newer_turn.feedback() == 'Incorrect.'

        assert round.number_correct() == 1

        assert round.number_correct_by_category('Geography') == 1
        assert round.number_correct_by_category('STEM') == 0

        assert round.percent_correct() == 50.0

        assert round.percent_correct_by_category('Geography') == 100.0
        assert round.percent_correct_by_category('STEM') == 0.0

        assert round.current_card() == card_3