Basic Concepts Flashcards
(19 cards)
In Python, what is used to output text?
In Python, we use the print statement to output text.
What does the print statement need to be followed by?
The print statement needs to be followed by parentheses, which enclose the output we want to generate.
What will the output of the following code be?
print ( ‘Hello world!’)
Hello world!
Fill in the blank to output “Hi”.
____(“Hi”)
print(“Hi”)
How can you get python to carry out a calculation?
Enter a calculation directly into the print statement
What will the output of this be:
print (2 + 2)
print (5+4-3)
4
6
How can you carry out multiplications and divisions in Python
Python also carries out multiplication and division, using an asterisk * to indicate multiplication and a forward slash / to indicate division.
What type of number does a single slash produce?
Using a single slash to divide numbers produces a decimal (or float, as it is called in programming).
What are floats used in Python to represent?
Floats are used in Python to represent numbers that aren’t integers (whole numbers).
Can computers store floats perfectly accurately?
Computers can’t store floats perfectly accurately, in the same way that we can’t write down the complete decimal expansion
How can you perform exponentials in Python?
This operation is performed using two asterisks.
Fill in the blank to output 5 raised to the 3rd power.
print(5___3)
print(5 ** 3)
How can you do floor division in Python?
Floor division is done using two forward slashes
What is floor division used to determine?
Floor division is used to determine the quotient of a division (the quantity produced by the division of two numbers).
What is the output of the following code?
print (20// 6)
3
How do you carry out the modulo operator?
The modulo operator is carried out with a percent symbol (%)
What is the modulo operator used to give?
The modulo operator is used to get the remainder of a division.
What is the output of the following code?
print (20 % 6)
print (1.25 % 0.5)
2
0.25
What is the result of this code?
print (7%(5 // 2) )
1