Is it love or just Python? How to develop a love calculator using a simple algorithm in Python
Publication date: June 16, 2020
by Ivana Vezjak, ICT teacher at Elementary school August Šenoa Osijek, Croatia
We have a new EU Code Week in front of us, taking place in October 2020. We are already coming up with ideas for new projects and new ways to celebrate it. Last year (2019), about 90 students from our school (Elementary School August Šenoa, Osijek), grades 5-8, participated in the EU Code Week. The students made their own chatbots and love calculators in the programming language Python and created virtual worlds which they later explored with VR glasses.
A group of 8th-grade students developed an application in Python, which we called the Love Calculator. It is an activity you should definitely try out. The application allows the entry of two names, and after clicking on the button, the “love percentage” is displayed on the screen.
Students first created their own backgrounds and pictures for the application. There are a lot of drawing tools available online, such as https://sketch.io/sketchpad. Making their own graphic materials is much more interesting to students than just downloading finished drawings from the internet. After creating the illustrations, students learned how to use Python’s module Tkinter to create a basic graphic window. This was in a way the design – they had to determine the background picture or colour, set the fields for entry of text and buttons, choose colours and fonts for their application etc. When they were satisfied with the visual look of the application, they started the coding.
The main part of the programme was comprised of writing two programming functions – one which generated a random number (the so-called love percentage) and another, which checked the entry of the user into the text field and displayed the love percentage to the screen. This was the more challenging part. Students had to think about how the programme functions, to create a good algorithm and write it all down in Python. We can find plenty of these kinds of programmes online, in the form of calculators or quizzes, which only give a random number, text or percentage as a result. Students have seen various programmes on the internet which function in a similar way, and by creating such a programme, they realised how such programmes operate. Through this project, they learned that online love calculators have nothing to do with love, but that behind them there exists a good algorithm in a particular programme language, and that the love percentage is nothing else but a randomly generated number. The students had great fun working on this project but also learned that they shouldn’t trust everything they see online. This activity also motivated them to actively create digital content, develop their computational thinking skills and learn how technology functions, instead of being passive users of technology.
This simple project is intended for students who already have basic experience in programming. The whole project can be found here. For the design of the project, students can use an online Python editor like repl.it, which works well with the Tkinter module, or they can work locally on their computers. Tkinter is part of the standard Python library, and it is not necessary to install it separately if Python is already installed on your computer.
We hope you will try it out for yourself and you will enjoy the activity as well!