Say hello with emojis
Your first print()
You can run simple code snippets on this site without leaving the browser. Run the code below using the ▶️ button. You are welcome to change the code, run it again and see how it worked.
python
print("This line will get printed after you run the code.")
What can I change in this code?
- Convert code above to a classic "Hello, world!" program.
- Assign the greeting text to a variable
message
and print its value. - Pick a different meaningful message to print — a slogan, a motto or a quote you may want to share.
- Make
message
a dictionary whereen
,kz
andru
are keys
and greeting text are values. Print message in a different language. - Make an LLM extend your code to other spoken languages. Check if LLM output is correct.
Pick a random emoji
The symbols you can print or not just letters, numbers or punctuation marks, but also emoji symbols. You need copy and paste them to your code from somewhere on the internet like this list.
There several new additions in code that allow choosing a random item from a list and reusing the print statement. Run the code several times to see the different emojis.
python
from random import choice
emojis = ["😊", "🎈", "🌟", "🐍", "👩💻", "👨💻"]
def hprint(message):
"""Print a message with a random emoji."""
print(message, choice(emojis))
hprint("I can write and run Python code")
hprint("I can do programming")
Proceed to the exercises below, but note that code you write will not be saved after you close the broswer — treat these excercises as a quick sketch.
Change some code
- Modify the emoji list — shorten or extend it with more symbols.
- Add more text:
- an additional message in plain text,
- new text followed by a new emoji,
- some text preceded by an emoji.
- Print several emojis together instead of one per line.
- Write comments in code about the changes you made.
Research the code
- Identify language constructs used:
- functions,
- variables,
- expressions and values,
- a function docstring.
- Look for the official documentation for the standard library modules and functions:
random.choice
,datetime.date
,sys.version
.
- Think of new ways to change the behaviour of this small program.
More exercises
- Add today's date to the printed messages. Start with code below.
python
# starting example
from datetime import date
dt = date.today()
- Optional: change the date format to
DD.MM.YYYY
. - Refactor
hprint
to accept emoji list as a function argument. - Make each of the messages display different sets of emoji, for example happy and sad or day and night emoji sets.
- Print the Python version number (like
3.12.1
) that was used. Retrieve it withsys.version
orsys.version_info
.
python
# starting example
from sys import version
print("My Python version is", "...")
Data science unexpected
- When running original code did you get the two emojis often? What is the theoretic probability of displaying two same emojis?
- Can you estimate this probability using a simulation? Write some code that geneates many emoji pairs and count the number and proportion of occurences when two emojis are the same.
- What is the probability to encounter two emojis of a shape 🎈 when running the original code? Prove your claim with theory or simulation.