-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
773 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Simple Chatty Bot | ||
|
||
## About | ||
|
||
Here, at the beginning of your programmer’s path, creating a simple console chat bot will do wonders to guide you through the basics of coding. During this journey you will also play some word and number games that you are going to implement all on your own. Pack up and let’s hit the road, my friend! | ||
|
||
## Learning outcomes | ||
|
||
You’ll get to know the basic syntax of Python and write a simple program using variables, conditions, loops, and functions. | ||
|
||
## Files | ||
|
||
| Name | Purpose | | ||
| ---- | ------- | | ||
| /Problems | Lesson tasks | | ||
| /Simple Chatty Bot | General project | |
48 changes: 48 additions & 0 deletions
48
Python Developer/Simple Chatty Bot/Simple Chatty Bot/Chatty Bot welcomes you/task-info.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
type: edu | ||
custom_name: stage1 | ||
files: | ||
- name: tests.py | ||
visible: false | ||
text: | | ||
import re | ||
from hstest.stage_test import * | ||
from hstest.test_case import TestCase | ||
CheckResult.correct = lambda: CheckResult(True, '') | ||
CheckResult.wrong = lambda feedback: CheckResult(False, feedback) | ||
class ChattyBotTest(StageTest): | ||
def generate(self) -> List[TestCase]: | ||
return [TestCase()] | ||
def check(self, reply: str, clue: Any) -> CheckResult: | ||
lines = reply.strip().splitlines() | ||
if len(lines) != 2: | ||
return CheckResult.wrong( | ||
"You should output exactly 2 lines!\n" + | ||
f"Lines found: {len(lines)}" | ||
f"Your output:\n" | ||
f"{reply.strip()}" | ||
) | ||
if not re.match(".*\\d.*", lines[1]): | ||
return CheckResult.wrong( | ||
"The second line should contain a year!\n" + | ||
"Your second line: \"" + lines[1] + "\"" | ||
) | ||
return CheckResult.correct() | ||
if __name__ == '__main__': | ||
ChattyBotTest('bot.bot').run_tests() | ||
learner_created: false | ||
- name: bot/bot.py | ||
visible: true | ||
text: | | ||
# write your code here | ||
learner_created: false | ||
feedback_link: https://hyperskill.org/projects/97/stages/534/implement#comment | ||
status: Unchecked | ||
record: -1 |
2 changes: 2 additions & 0 deletions
2
...veloper/Simple Chatty Bot/Simple Chatty Bot/Chatty Bot welcomes you/task-remote-info.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id: 8799 | ||
update_date: Mon, 11 Jan 2021 20:59:56 UTC |
27 changes: 27 additions & 0 deletions
27
Python Developer/Simple Chatty Bot/Simple Chatty Bot/Chatty Bot welcomes you/task.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<h2 style="text-align: center;">Description</h2> | ||
|
||
<p>Digital personal assistants help people to drive cars, plan their day, buy something online. In a sense, they are simplified versions of artificial intelligence with whom you can talk.</p> | ||
|
||
<p>In this project, you will develop step by step a simple bot that will help you study programming.</p> | ||
|
||
<h2 style="text-align: center;">Objective</h2> | ||
|
||
<p>For the first stage, you will write a bot who displays a greeting, its name, and the date of its creation. First impressions count!</p> | ||
|
||
<p>Your program should print the following lines:</p> | ||
|
||
<pre><code class="language-no-highlight">Hello! My name is {bot_name}. | ||
I was created in {birth_year}.</code></pre> | ||
|
||
<p>Instead of <code class="java">{bot_name}</code>, print any name you choose and replace <code class="java">{birth_year}</code> with the current year (four digits).</p> | ||
|
||
<h2 style="text-align: center;">Example</h2> | ||
|
||
<p>Output:</p> | ||
|
||
<pre><code class="language-no-highlight">Hello! My name is Aid. | ||
I was created in 2020.</code></pre> | ||
|
||
<p>You can change the text if you want but print exactly two lines.</p> | ||
|
||
<p>Next, we will use <strong>Aid</strong> and <strong>2020</strong> as your bot's name and its birth year, but you can change it if you need to.</p> |
77 changes: 77 additions & 0 deletions
77
Python Developer/Simple Chatty Bot/Simple Chatty Bot/Guess the age/task-info.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
type: edu | ||
custom_name: stage3 | ||
files: | ||
- name: tests.py | ||
visible: false | ||
text: | | ||
from hstest.stage_test import * | ||
from hstest.test_case import TestCase | ||
CheckResult.correct = lambda: CheckResult(True, '') | ||
CheckResult.wrong = lambda feedback: CheckResult(False, feedback) | ||
class ChattyBotTest(StageTest): | ||
def generate(self) -> List[TestCase]: | ||
return [ | ||
TestCase(stdin="John\n1\n2\n1", attach=("John", 22)), | ||
TestCase(stdin="Nick\n2\n0\n0", attach=("Nick", 35)) | ||
] | ||
def check(self, reply: str, clue: Any) -> CheckResult: | ||
lines = reply.strip().splitlines() | ||
if len(lines) != 7: | ||
return CheckResult.wrong( | ||
"You should output 7 lines!\n" + | ||
f"Lines found: {len(lines)}" | ||
f"Your output:\n" | ||
f"{reply.strip()}" | ||
) | ||
line_with_name = lines[3].lower() | ||
name = clue[0].lower() | ||
if name not in line_with_name: | ||
return CheckResult.wrong( | ||
"The name was " + clue[0] + "\n" + | ||
"But the 4-th line was:\n" + | ||
"\"" + lines[3] + "\"\n\n" + | ||
"4-th line should contain a name of the user" | ||
) | ||
line_with_age = lines[6].lower() | ||
age = str(clue[1]) | ||
if age not in line_with_age: | ||
return CheckResult.wrong( | ||
"Can't find a correct age " + | ||
"in the last line of output! " + | ||
"Maybe you calculated the age wrong?\n\n" + | ||
"Your last line: \n" + "\"" + lines[6] + "\"" | ||
) | ||
return CheckResult.correct() | ||
if __name__ == '__main__': | ||
ChattyBotTest('bot.bot').run_tests() | ||
learner_created: false | ||
- name: bot/bot.py | ||
visible: true | ||
text: | | ||
print('Hello! My name is Aid.') | ||
print('I was created in 2020.') | ||
print('Please, remind me your name.') | ||
name = input() | ||
print('What a great name you have, ' + name + '!') | ||
print('Let me guess your age.') | ||
print('Enter remainders of dividing your age by 3, 5 and 7.') | ||
# reading all remainders | ||
print("Your age is {your_age}; that's a good time to start programming!") | ||
learner_created: false | ||
feedback_link: https://hyperskill.org/projects/97/stages/536/implement#comment | ||
status: Unchecked | ||
record: -1 |
2 changes: 2 additions & 0 deletions
2
Python Developer/Simple Chatty Bot/Simple Chatty Bot/Guess the age/task-remote-info.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id: 8801 | ||
update_date: Mon, 11 Jan 2021 22:27:19 UTC |
49 changes: 49 additions & 0 deletions
49
Python Developer/Simple Chatty Bot/Simple Chatty Bot/Guess the age/task.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<h2 style="text-align: center;">Description</h2> | ||
|
||
<p>Keep improving your bot by developing new skills for it. We suggest a simple guessing game that will predict the age of a user.</p> | ||
|
||
<p>It's based on a simple math trick. First, take a look at this formula:</p> | ||
|
||
<pre><code class="java">age = (remainder3 * 70 + remainder5 * 21 + remainder7 * 15) % 105</code></pre> | ||
|
||
<p>The numbers<code class="java">remainder3</code>, <code class="java">remainder5</code> and <code class="java">remainder7</code> are the remainders of division by 3, 5 and 7 respectively.</p> | ||
|
||
<p>It turns out that for each number ranging from <em>0</em> to <em>104</em> the calculation will result in the number itself. This perfectly fits the ordinary age range, doesn't it? Ask a user for the remainders and use them to guess the age!</p> | ||
|
||
<h2 style="text-align: center;">Objective</h2> | ||
|
||
<p>At this stage, you will introduce yourself to the bot. It will greet you by your name and then try to guess your age using arithmetic operations.</p> | ||
|
||
<p>Your program should print the following lines:</p> | ||
|
||
<pre><code class="language-no-highlight">Hello! My name is Aid. | ||
I was created in 2020. | ||
Please, remind me your name. | ||
What a great name you have, Max! | ||
Let me guess your age. | ||
Enter remainders of dividing your age by 3, 5 and 7. | ||
Your age is {your_age}; that's a good time to start programming!</code></pre> | ||
|
||
<p>Read three numbers from the standard input. Assume that all the numbers will be given on separate lines.</p> | ||
|
||
<p>Instead of <code class="java">{your_age}</code>, the bot will print the age determined according to the special formula discussed above.</p> | ||
|
||
<h2 style="text-align: center;">Example</h2> | ||
|
||
<p>The greater-than symbol followed by a space (<code class="java">> </code>) represents the user input. Note that it's not part of the input.</p> | ||
|
||
<p><strong>Example 1:</strong> <em>a dialogue with the bot</em></p> | ||
|
||
<pre><code class="language-no-highlight">Hello! My name is Aid. | ||
I was created in 2020. | ||
Please, remind me your name. | ||
> Max | ||
What a great name you have, Max! | ||
Let me guess your age. | ||
Enter remainders of dividing your age by 3, 5 and 7. | ||
> 1 | ||
> 2 | ||
> 1 | ||
Your age is 22; that's a good time to start programming!</code></pre> | ||
|
||
<p>Use the provided template to simplify your work. You can change the text, but not the number of printed lines.</p> |
100 changes: 100 additions & 0 deletions
100
Python Developer/Simple Chatty Bot/Simple Chatty Bot/Learning numbers/task-info.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
type: edu | ||
custom_name: stage4 | ||
files: | ||
- name: tests.py | ||
visible: false | ||
text: | | ||
from hstest.stage_test import * | ||
from hstest.test_case import TestCase | ||
CheckResult.correct = lambda: CheckResult(True, '') | ||
CheckResult.wrong = lambda feedback: CheckResult(False, feedback) | ||
class ChattyBotTest(StageTest): | ||
def generate(self) -> List[TestCase]: | ||
return [ | ||
TestCase(stdin="Marry\n1\n0\n5\n10", attach=("Marry", 40, 10)) | ||
] | ||
def check(self, reply: str, clue: Any) -> CheckResult: | ||
lines = reply.strip().splitlines() | ||
length = 9 + clue[2] + 1 | ||
if len(lines) != length: | ||
return CheckResult.wrong( | ||
f"You should output {length} lines " + | ||
f"(for the count number {clue[2]}).\n" + | ||
f"Lines found: {len(lines)}\n" | ||
f"Your output:\n" | ||
f"{reply.strip()}" | ||
) | ||
line_with_name = lines[3].lower() | ||
name = clue[0].lower() | ||
if name not in line_with_name: | ||
return CheckResult.wrong( | ||
"The name was " + clue[0] + "\n" + | ||
"But the 4-th line was:\n" + | ||
"\"" + lines[3] + "\"\n\n" + | ||
"4-th line should contain a name of the user" | ||
) | ||
line_with_age = lines[6].lower() | ||
age = str(clue[1]) | ||
if age not in line_with_age: | ||
return CheckResult.wrong( | ||
"Can't find a correct age " + | ||
"in the last line of output! " + | ||
"Maybe you calculated the age wrong?\n\n" + | ||
"Your last line: \n" + "\"" + lines[6] + "\"" | ||
) | ||
for i in range(clue[2] + 1): | ||
num_line = lines[i + 8].strip().replace(' ', '') | ||
actual_num = f'{i}!' | ||
if num_line != actual_num: | ||
return CheckResult.wrong( | ||
f"Expected {i + 8}-th line: \n" + | ||
f"\"{actual_num}\"\n" + | ||
f"Your {i + 8}-th line: \n" + | ||
f"\"{num_line}\"" | ||
) | ||
return CheckResult.correct() | ||
if __name__ == '__main__': | ||
ChattyBotTest('bot.bot').run_tests() | ||
learner_created: false | ||
- name: bot/bot.py | ||
visible: true | ||
text: | | ||
print('Hello! My name is Aid.') | ||
print('I was created in 2020.') | ||
print('Please, remind me your name.') | ||
name = input() | ||
print('What a great name you have, ' + name + '!') | ||
print('Let me guess your age.') | ||
print('Enter remainders of dividing your age by 3, 5 and 7.') | ||
rem3 = int(input()) | ||
rem5 = int(input()) | ||
rem7 = int(input()) | ||
age = (rem3 * 70 + rem5 * 21 + rem7 * 15) % 105 | ||
print("Your age is " + str(age) + "; that's a good time to start programming!") | ||
print('Now I will prove to you that I can count to any number you want.') | ||
# read a number and count to it here | ||
print('Completed, have a nice day!') | ||
learner_created: false | ||
feedback_link: https://hyperskill.org/projects/97/stages/537/implement#comment | ||
status: Unchecked | ||
record: -1 |
2 changes: 2 additions & 0 deletions
2
Python Developer/Simple Chatty Bot/Simple Chatty Bot/Learning numbers/task-remote-info.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id: 8802 | ||
update_date: Wed, 13 Jan 2021 18:52:36 UTC |
38 changes: 38 additions & 0 deletions
38
Python Developer/Simple Chatty Bot/Simple Chatty Bot/Learning numbers/task.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<h2 style="text-align: center;">Description</h2> | ||
|
||
<p>Now you will teach your bot to count. It's going to become an expert in numbers!</p> | ||
|
||
<h2 style="text-align: center;">Objective</h2> | ||
|
||
<p>At this stage, you will program the bot to count from 0 to any positive number users enter.</p> | ||
|
||
<h2 style="text-align: center;">Example</h2> | ||
|
||
<p>The greater-than symbol followed by a space (<code class="java">> </code>) represents the user input. Note that it's not part of the input.</p> | ||
|
||
<p><strong>Example 1:</strong> <em>a dialogue with the new version of the bot</em></p> | ||
|
||
<pre><code class="language-no-highlight">Hello! My name is Aid. | ||
I was created in 2020. | ||
Please, remind me your name. | ||
> Max | ||
What a great name you have, Max! | ||
Let me guess your age. | ||
Enter remainders of dividing your age by 3, 5 and 7. | ||
> 1 | ||
> 2 | ||
> 1 | ||
Your age is 22; that's a good time to start programming! | ||
Now I will prove to you that I can count to any number you want. | ||
> 5 | ||
0 ! | ||
1 ! | ||
2 ! | ||
3 ! | ||
4 ! | ||
5 ! | ||
Completed, have a nice day!</code></pre> | ||
|
||
<p><strong>Note: </strong>each number starts with a new line, and after a number, the bot should print the exclamation mark.</p> | ||
|
||
<p>Use the provided template to simplify your work. You can change the text if you want, but be especially careful when counting numbers.</p> |
Oops, something went wrong.