It’s fun and easy to become a programmer.
his hour of code will show you the fun and entertaining side of coding
When you use a software website/app, you expect it to do something and show you output. To display output you need to use a special keyword print .
Think about your Facebook profile picture for a second. You can change
it at any time. This means your profile pic could vary or change.
If someone asks you-
1. Is it hot today?
2. Is he crazy?
3. Is this Jacket expensive?
4. Is this cat drunk? 😾
The answers to these questions are either True or False. A variable whose value could be either True or False is called a boolean type variable.
While creating your user account in Facebook, youtube, or any other website/app you need to provide your name, email address, password, etc.
This means, the website/app needs to take user input from you.
Most of the time, your morning starts with one command from your mom- brush your teeth. That’s all she tells you, and you know what you have to do.
Let's make learning fun by building your own game while learning to code.
Use print() to show output.
Similarly, the number of likes is not same for everything you see on facebook or youtube.
Sometimes it’s higher, and sometimes it’s lower. This means numbers of likes could vary or change.
In fact, a lot of things you see around you could vary or change.
Now you know there are a lot of things that could change. They could vary.
For simplicity, you can think
Variable = Vary + able
Hence, variable is something that could vary.
As a programmer, you will write variables every day. And it’s very
simple to write a variable. You will need just three things-
1. A name
2. An equal sign(=)
3. A value
When the value of a variable contains one or more characters or words, it is called a string . type variable.
When you write the value of a string type variable, you put them inside double quotes
name = "Mark Zuckerberg"
sports = "football"
food = "noddles
Use double quotes for string type variable.
Writing a boolean type variable is very simple. First, you write the variable name and then equals sign and then True or False.
For example, if you are rich, you will write-
isRich = True
isScared = False
Boolean values will be True or False
To ask for any information in the Python programming language is very simple. Just type input(). This will ask the user to provide some information.
While asking for user input, you can add extra info to tell the user what information they should provide
input("Tell me your favorite food:")
Besides, you can store user input in a variable and then use that variable.
Use input() to take user input.
Similarly, if she tells you to clean the dishes, do the laundry, throw out the garbage, or take a shower, you know all the steps you need to perform to finish these tasks.
These tasks have three unique properties-
These tasks are called functions . This means, you are doing some tasks or performing a function.
Let’s declare your first function. And give it the name brush_teeth.
Inside the function, you will do few things.
You will call this function by writing the function’s name and then two parentheses like below as if you are giving a command to perform the task.
You are doing great. Keep going.
Use a function to do one or more sub-tasks when needed.
You can put more than one value in a variable in a unique way.
When you put more than one values in a variable, that variable is called a list or collection or array.
We will refer to it as a list.
Each item in a list is called an element of the list.
While declaring a list, you need to do two things-
friends_age = [17, 19, 21, 15, 16]
You are on a bus with your superhero friends. Since there is more than one person on the bus, you can create a list with their names.
To create a list with names, you have to write names inside third brackets and a comma between two elements. Also, names are a string. Thus, you have to enclose each name with quotation marks.
friends = [ "Batman", "Cat Man", "Fat Man", "Cockroach Man"]
You are desperate to have a friend. That's why you keep sending messages to strangers until thery reply or block you. This means you are sending messages until a condition is fulfilled. Untill they block you.
You are doing something multiple times based on a condition.
While doing something based on a condition, you can use a loop. This loop is called a while loop.
You can write a while loop as follows. (Don’t worry if you do not get it, we will explain it later.)
count = 0
while count < 5:
count = count + 1
To write a while loop you have to do five things
If the loop condition becomes True, the loop will continue. If the condition becomes False the loop will stop running.
You are Finished The All Lesson. Now your next step to download Programming Hero & build your own Game.