[006] Introduction to Python Basics: Simple and Short Exercises

Koay Yong Cett
3 min readJun 25, 2020

--

Photo by Sincerely Media on Unsplash

Let’s practice on some coding based on the things that we learned before. Let’s talk about the input of data.

Exercise 1: Conversion Type

  • We get an error and if you try writing this code alone, you may also encountered this. We get something called type error and we can get tons of error in Python.
  • Let’s try to debug this look like we are using a minus on an integer and a string.
  • The number we entered 1997 is a class string. The 1997 that we input gets converted to a string and assigned to the birth year. What does this means? It means that we are trying to subtract a string from a number.
  • Then, how do you solve this problems? We need to convert the string into an integer.
  • Now, we created a program that was able to tell your age based on the year you are born. This might be a little bit tricky where we store data into different data types. Then, we need them to interact with each others. Well, there will be a lot of errors and this is the common one.

Exercise 2: Password Checker

Let’s create a simple password checker for practice. Now, we are going to create some sort of an input with input function in this simple program.

  • Let’s say we input the username and password, then we want to print the username and password. Obviously, we don’t want to show or display the password or maybe for security reasons.
  • Then, how are we going to convert the secret into star(*) and make the secret hidden?
  • You may want to use this functionality when you are doing this exercise.
  • This is the simple example code that will be used and understand easily.
  • This is working because that with an f string we can create or add a python expression in the line of code with len(password).
  • However, there is an issue here. We don’t want to print out the secret instead in the star(*) form.
  • All the line of code is easy and neat to understand. The objective of making the secret into star(*) is achieved. Although this is a simple example, this idea of readability and writing code that make sense is an important concept.

Thanks for reading my stories 😄

--

--

Koay Yong Cett
Koay Yong Cett

Written by Koay Yong Cett

Every stories I shared is based on my personal opinion. Interest in ethical hacking and penetration testing. Thank you.

No responses yet