5) Then Python saw that we want to display the result's value because of the print (result) and print it accordingly.
As you can see, numbers and variables work well together in Python.
Let's practice some more and create your examples with numbers and variables, similar to what we just saw. Here are some boilerplate examples for you:
___________
result = 2+2
print(result)
___________
result = 10-5
print(result)
___________
result = 5*5
print(result)
___________
result = 10/2
print(result)
___________
7 Wrapping Up Chapter Three
In chapter three, we have accomplished the following:
1) Refreshed on what are integers and fractional numbers;
2) Learned basic math operators used in Python;
3) Learned how to divide a number without remainder in Python;
4) Got to know the order of calculation in Python;
5) Combined numbers and variables in math examples.
1. What types of numbers are there in Python?
1) There are three types of numbers in Python: Integers, almost whole numbers, and fractional.
2) There are two types of numbers in Python: Integers and half integers.
3) There are two types of numbers in Python: Integers – integer and fractional numbers.
2. How does Python divide 10 by 5? (Multiple selection)
1) 10:5
2) 10/5
3) 10-5
4) 10 * 5
5) 10 // 5
3. Arrange the parts of the code so that you get the integer 4.
five
10*2
//
4. This code should display 5. But what is missing?
result = 10/2
_____(result)
Do you remember the messages we displayed in chapter one, like "Hey! This is my first line of code!" or "Once upon a time.." They are all strings. In other words, a string is a data type that has a text format, or just a text, enclosed in quotes. Hence, to create a string, we have to type a text and enclose it in quotes.
2 Strings And Print Function
Let's write a code that would display the string – "Now I know what a string is in Python." You already know how to display strings in Python, right? Here is the code.
print("Now I know what a string is in Python.")
Write the above line into the console and hit run. Now it's your turn. Think of some different string, rewrite and run the above code.
3 Saving Strings in Variables
Do you remember our first variable: film = "Super Cat"? Now you know that the value of the variable – "Super Cat" had a string format, as we enclose it in quotes. Let's take our knowledge further, create a message in a string format, save it in a variable, and display the variable value on your screen using the print function. Let me do it first: