rename mad_lib
This commit is contained in:
0
1/1.9 Mad Lib/mad_lib/__main__.py
Normal file
0
1/1.9 Mad Lib/mad_lib/__main__.py
Normal file
33
1/1.9 Mad Lib/mad_lib/mad_lib.py
Normal file
33
1/1.9 Mad Lib/mad_lib/mad_lib.py
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
# Construct a mad lib
|
||||
class mad_lib:
|
||||
|
||||
def __init__(self, lib):
|
||||
self.text = lib
|
||||
self.text = self.text.replace('%first_name%', self.first_name())
|
||||
self.text = self.text.replace('%location%', self.location())
|
||||
self.text = self.text.replace('%whole_number%', self.whole_number())
|
||||
self.text = self.text.replace('%plural_noun%', self.plural_noun())
|
||||
|
||||
|
||||
def first_name(self):
|
||||
#return input("A first name: ")
|
||||
return input()
|
||||
|
||||
def location(self):
|
||||
#return input("A location: ")
|
||||
return input()
|
||||
|
||||
def whole_number(self):
|
||||
#return input("A whole number: ")
|
||||
return input()
|
||||
|
||||
def plural_noun(self):
|
||||
#return input("A plural noun: ")
|
||||
return input()
|
||||
|
||||
|
||||
# Construct a mad lib
|
||||
md = mad_lib('%first_name% went to %location% to buy %whole_number% different types of %plural_noun%')
|
||||
|
||||
print(md.text)
|
||||
0
1/1.9 Mad Lib/tests/__init__.py
Normal file
0
1/1.9 Mad Lib/tests/__init__.py
Normal file
19
1/1.9 Mad Lib/tests/test_zyBooks.py
Normal file
19
1/1.9 Mad Lib/tests/test_zyBooks.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
import mad_lib
|
||||
|
||||
|
||||
class zyBooks_Test(unittest.TestCase):
|
||||
|
||||
|
||||
|
||||
|
||||
@patch('builtins.input', return_value=['Eric', 'Chipotle', '12', 'cars'])
|
||||
def test_zyBooks(self, mock_input):
|
||||
result = mad_lib()
|
||||
|
||||
self.assertEqual(result, 6)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user