-
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.
Completion of the Simple Chatty Bot project
- Loading branch information
Showing
21 changed files
with
270 additions
and
18 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
Python Developer/Simple Chatty Bot/Problems/Correct a mistake/main.py
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,8 @@ | ||
def compare(numerator, denominator): | ||
return (denominator != 0) and (numerator / denominator == 0.5) | ||
|
||
|
||
a = int(input()) | ||
b = int(input()) | ||
|
||
print(compare(a, b)) |
20 changes: 20 additions & 0 deletions
20
Python Developer/Simple Chatty Bot/Problems/Correct a mistake/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,20 @@ | ||
type: code | ||
files: | ||
- name: main.py | ||
visible: true | ||
text: |- | ||
def compare(numerator, denominator): | ||
return denominator and numerator / denominator == 0.5 | ||
a = int(input()) | ||
b = int(input()) | ||
print(compare(a, b)) | ||
learner_created: false | ||
feedback_link: https://hyperskill.org/learn/step/10333#comment | ||
status: Solved | ||
feedback: | ||
message: <html>Correct solution</html> | ||
time: Sun, 31 Jan 2021 10:06:06 UTC | ||
record: -1 |
2 changes: 2 additions & 0 deletions
2
Python Developer/Simple Chatty Bot/Problems/Correct a mistake/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: 10333 | ||
update_date: Mon, 21 Dec 2020 11:57:20 UTC |
18 changes: 18 additions & 0 deletions
18
Python Developer/Simple Chatty Bot/Problems/Correct a mistake/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,18 @@ | ||
<h2>Correct a mistake</h2> | ||
<html> | ||
<head></head> | ||
<body> | ||
<p><span style="background-color: #ffffff; color: #222222; font-size: 12pt; font-variant: normal;"></span></p> | ||
<p>The code below solves the following problem — having the numerator and the denominator of a fraction, check if the fraction equals <code class="language-python">0.5</code>. The program should print <code class="language-python">True</code> or <code class="language-python">False</code>. If the denominator equals <code class="language-python">0</code>, the answer is <code class="language-python">False</code>.</p> | ||
<pre><code class="language-python">def compare(numerator, denominator): | ||
return denominator and numerator / denominator == 0.5 | ||
|
||
|
||
a = int(input()) | ||
b = int(input()) | ||
|
||
print(compare(a, b))</code></pre> | ||
<p>But this code works incorrectly. Find and correct the mistake, then run the code.</p> | ||
</body> | ||
</html><br><b>Sample Input:</b><br><pre><code class="language-no-highlight">5<br>10</code></pre><br><b>Sample Output:</b><br><pre><code class="language-no-highlight">True</code></pre><br><br><b>Sample Input:</b><br><pre><code class="language-no-highlight">3<br>0</code></pre><br><b>Sample Output:</b><br><pre><code class="language-no-highlight">False</code></pre><br><br><b>Sample Input:</b><br><pre><code class="language-no-highlight">-1<br>-2</code></pre><br><b>Sample Output:</b><br><pre><code class="language-no-highlight">True</code></pre><br><br><br><font color="gray">Memory limit: 256 MB</font><br><font color="gray">Time limit: 15 seconds</font><br><br> | ||
<a href="https://hyperskill.org/learn/step/10327">Show topic summary</a> |
3 changes: 3 additions & 0 deletions
3
Python Developer/Simple Chatty Bot/Problems/Find the password/main.py
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,3 @@ | ||
def solve(): | ||
# Write your code here | ||
print(wrong_password(False)) |
11 changes: 11 additions & 0 deletions
11
Python Developer/Simple Chatty Bot/Problems/Find the password/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,11 @@ | ||
type: code | ||
files: | ||
- name: main.py | ||
visible: true | ||
text: |- | ||
def solve(): | ||
# Write your code here | ||
learner_created: false | ||
feedback_link: https://hyperskill.org/learn/step/10334#comment | ||
status: Solved | ||
record: -1 |
2 changes: 2 additions & 0 deletions
2
Python Developer/Simple Chatty Bot/Problems/Find the password/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: 10334 | ||
update_date: Tue, 22 Dec 2020 14:56:30 UTC |
21 changes: 21 additions & 0 deletions
21
Python Developer/Simple Chatty Bot/Problems/Find the password/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,21 @@ | ||
<h2>Find the password</h2> | ||
<html> | ||
<head></head> | ||
<body> | ||
<p><span style="background-color: #ffffff; color: #222222; font-size: 12pt; font-variant: normal;"></span></p> | ||
<p>Imagine that you are a hacker and you have got access to a web server written in Python. The problem is that it asks for a password that you do not know. However, this server is open source so you know that there is the <code class="language-python">wrong_password()</code> function which takes a password and checks it against <code class="language-python">real_password</code>.</p> | ||
<pre><code class="language-python">def wrong_password(password): | ||
return (password == "" or (not password and real_password)) or password != real_password</code></pre> | ||
<p>You can not access the <code class="language-python">real_password</code> variable but you can call the <code class="language-python">wrong_password()</code> function and exploit its vulnerability to obtain the password. Write your code inside the <code class="language-python">solve()</code> function. Think about an argument that can be passed to the <code class="language-python">wrong_password()</code> function so that the function returns the <code class="language-python">real_password</code>. <strong>Print</strong> the result of the <code class="language-python">wrong_password()</code> function.</p> | ||
<p>Your program should not read any input or call the <code class="language-python">solve()</code> function, your task is to implement it.</p> | ||
<p><button class="btn-sm btn-outline-secondary" onclick="getElementById('hint-1263').style.display='inline'"> Hint </button> </p> | ||
<div id="hint-1263" style="display:none;"> | ||
Remember that "and" and "or" operators return one of their operands. Refer to the tables showing which operands the operators return in different cases. | ||
</div> | ||
<p></p> | ||
</body> | ||
</html><br><br><font color="gray">Memory limit: 256 MB</font><br><font color="gray">Time limit: 15 seconds</font><br><br> | ||
<b>Caution</b><br><br> | ||
You may see errors in your code or execution results due to missing context. Don’t worry about it, just write the solution and press Check. | ||
<br><br> | ||
<a href="https://hyperskill.org/learn/step/10327">Show topic summary</a> |
8 changes: 8 additions & 0 deletions
8
Python Developer/Simple Chatty Bot/Problems/XOR operator/main.py
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,8 @@ | ||
def xor(a, b): | ||
if bool(a) == bool(b): | ||
return False | ||
else: | ||
if a: | ||
return a | ||
else: | ||
return b |
14 changes: 14 additions & 0 deletions
14
Python Developer/Simple Chatty Bot/Problems/XOR operator/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,14 @@ | ||
type: code | ||
files: | ||
- name: main.py | ||
visible: true | ||
text: |- | ||
def xor(a, b): | ||
# Write your code here | ||
learner_created: false | ||
feedback_link: https://hyperskill.org/learn/step/10332#comment | ||
status: Solved | ||
feedback: | ||
message: <html>Correct solution</html> | ||
time: Sun, 31 Jan 2021 10:12:44 UTC | ||
record: -1 |
2 changes: 2 additions & 0 deletions
2
Python Developer/Simple Chatty Bot/Problems/XOR operator/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: 10332 | ||
update_date: Sat, 19 Dec 2020 03:04:30 UTC |
27 changes: 27 additions & 0 deletions
27
Python Developer/Simple Chatty Bot/Problems/XOR operator/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>XOR operator</h2> | ||
<html> | ||
<head></head> | ||
<body> | ||
<p><span style="background-color: #ffffff; color: #222222; font-size: 12pt; font-variant: normal;"></span></p> | ||
<p>Implement an XOR operator that can work with objects of any type.</p> | ||
<p>The behaviour should be the following:</p> | ||
<ul> | ||
<li>if the operands are both truthy or both falsy, <strong>return </strong><code class="java">False</code>,</li> | ||
<li>if one operand is truthy and the other operand is falsy, <strong>return </strong>the <strong>truthy one</strong> (the operand itself, not <code class="java">True</code>).</li> | ||
</ul> | ||
<p>Write your code inside the <code class="java">xor()</code> function. Your program should not read any input or call the function, your task is to implement it.</p> | ||
<p><button class="btn-sm btn-outline-secondary" onclick="getElementById('hint-713').style.display='inline'"> Hint </button> </p> | ||
<div id="hint-713" style="display:none;"> | ||
Remember some facts: the | ||
<code class="java">bool()</code> function returns | ||
<code class="java">True</code> if the passed argument is truthy, and | ||
<code class="java">False</code> if it is falsy. What operand does the | ||
<code class="java">or</code> operator return? | ||
</div> | ||
<p></p> | ||
</body> | ||
</html><br><br><font color="gray">Memory limit: 256 MB</font><br><font color="gray">Time limit: 15 seconds</font><br><br> | ||
<b>Caution</b><br><br> | ||
You may see errors in your code or execution results due to missing context. Don’t worry about it, just write the solution and press Check. | ||
<br><br> | ||
<a href="https://hyperskill.org/learn/step/10327">Show topic summary</a> |
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,4 @@ | ||
content: | ||
- Correct a mistake | ||
- XOR operator | ||
- Find the password |
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
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
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
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
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
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ content: | |
- Guess the age | ||
- Learning numbers | ||
- Multiple choice | ||
current_task: 0 | ||
current_task: 4 |
57 changes: 56 additions & 1 deletion
57
Python Developer/Simple Chatty Bot/Simple Chatty Bot/task/bot/bot.py
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 |
---|---|---|
@@ -1 +1,56 @@ | ||
# write your code here | ||
def greet(bot_name, birth_year): | ||
print('Hello! My name is ' + bot_name + '.') | ||
print('I was created in ' + birth_year + '.') | ||
|
||
|
||
def remind_name(): | ||
print('Please, remind me your name.') | ||
name = input() | ||
print('What a great name you have, ' + name + '!') | ||
|
||
|
||
def guess_age(): | ||
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!") | ||
|
||
|
||
def count(): | ||
print('Now I will prove to you that I can count to any number you want.') | ||
|
||
num = int(input()) | ||
curr = 0 | ||
while curr <= num: | ||
print(curr, '!') | ||
curr = curr + 1 | ||
|
||
|
||
def test(): | ||
print("Let's test your programming knowledge.") | ||
print('') | ||
print('''Why do we use methods? | ||
1. To repeat a statement multiple times. | ||
2. To decompose a program into several small subroutines. | ||
3. To determine the execution time of a program. | ||
4. To interrupt the execution of a program.''') | ||
while (user_input := input()) != '4': | ||
user_input = input('Please, try again.\n') | ||
print('Completed, have a nice day!') | ||
|
||
|
||
def end(): | ||
print('Congratulations, have a nice day!') | ||
|
||
|
||
greet('Aid', '2020') # change it as you need | ||
remind_name() | ||
guess_age() | ||
count() | ||
test() | ||
end() |
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