Chief Marketing Officer Practicum by Yandex, edtech expert, practicum.yandex.com
I assume you know nothing about programming and want to try and make something with the world’s programming sweetheart — Python.
The program will be very simple:
Although the algorithm is simple, the implementation of each step can make this app very useful. For example, in steps 1 and 2, I can communicate through different channels: keyboard, voice, or messaging apps.
I can also alter the algorithm itself, for example, to make it death-proof: if your computer shuts down during step 4, it needs to know what it has to remind you about. But for now, let’s stick with the simple stuff.
I make a simple thing: take every step of our algorithm and show how it can be implemented in Python. First, though, I need to get things ready. Here is a Python command that I need to use:
Import tells Python to load a module with the tools that I need for the task. Time is the name of the module. From that module, I’ll need a method called ‘sleep’ that I’ll use to pause the program for a set amount of time.
I need to ask the user and get a response. In a perfect world, I’d want a code like this:
reminder = user.ask("What shall I remind you about?")
And somewhere in the program, I’ll need to define what user and ask mean. It may be a message sent over Telegram, or it could be a voice prompt, or maybe have a robot approach user with a happy face and display the message on the screen. Implementation could be different, and I’d define it in a separate place in our program.
But I want a simple implementation, so I’ll go with some built-in commands:
print("What shall I remind you about?")
Print sends out a text message into Python’s default output (which in our case is command line).
text = str(input())
Take whatever the user has written, think of it as text, and put it into memory under the name “text”. Input() reads whatever the user inputs. Str() turns whatever had been input into text. Equals means “put one thing into memory with such name.”
I need time in minutes. Here goes:
print("In how many minutes?") local_time = float(input())
The second line means: Take whatever user typed, think of it as a number, put it in memory under the name “local_time”.
I have a number of minutes that our app needs to wait before reminding us. But Python’s time.sleep() method requires seconds, not minutes. So I need to convert minutes to seconds:
local_time = local_time * 60
This reads: take whatever is in memory under the name “local_time”, multiply it by 60, and put it in memory under the name “local_time”.
Now I’ll need that time module that I loaded in step 0:
This reads: From module “time,” take the method “sleep.” From memory, find a piece of data under the name “local_time.” Give that piece of data to “sleep” and see what happens.
What happens: I have a number of seconds in ‘local_time’. I give that number to ‘Sleep,’ and the program sleeps for the specified number of seconds. I know it sleeps because I had read the reference manual for the module’ time’.
Remember that I have our reminder text stored in memory under the name ‘text’? It’s time to use it:
This means: take whatever is in memory under ‘text’ and send it to output.
Similar to step 1, U could have set up a whole different implementation of sending out messages. I could have created a routine that 3D-prints our message in plastic or lights up some LEDs in the form of our text. But all I need now is this primary mechanism that sends out the text.
This is the code that will work:
import time print("What shall I remind you about?") text = str(input()) print("In how many minutes?") local_time = float(input()) local_time = local_time * 60 time.sleep(local_time) print(text)
If you input this into your Jupyter notebook and run (Shift + Enter), you’ll see your program in action:
And if you want more practice on Python you can try our free course on Practicum by Yandex.
Create your free account to unlock your custom reading experience.