What is the purpose of the print function in Python?
Print Function: Prints a specified message on the screen. If Else Conditionals: Control the flow of your program by running different code depending on certain conditions. Python is an object-oriented language and uses indentation to structure code.
Python Basics: Print Function and If Else Conditionals
Print Function: A function that prints a specified message on the screen. If Else Conditionals: A control flow structure that runs one block of code if a certain condition is true, and another block of code if the condition is false. Object-Oriented Language: A language designed to allow the creation of objects that contain data and methods.
Concepts:
Python was named after the British comedy series Monty Python's Flying Circus. Python is one of the most popular programming languages in the world. The print() function was added to Python with version 2.6.
Fun facts:
Work together in pairs: How can you use the print function and if else conditionals in your own programming projects?
Work together in pairs: In your own words, explain what is meant by the Python print function and if else conditionals?
Brain break: Draw a picture of a dragon riding a unicorn through the clouds!
What is the Print Function used for in Python?
- A. To output text to the console
- B. To delete text from the console
- C. To display a graphical user interface
- D. To store data in the computer memory
Which of the following is an example of an if-else conditional?
- A. for i in range (0,3):
- B. if x > y:
- C. print ('Hello World')
- D. while x < y:
What is the output of the following code? x = 10; y = 15; if x > y: print ('x is greater than y')
- A. x is greater than y
- B. y is greater than x
- C. x is equal to y
- D. None of the above
What is the purpose of the else statement in an if-else conditional?
- A. To execute a set of statements if the condition is false
- B. To execute a set of statements if the condition is true
- C. To delete a set of statements
- D. To store data in the computer memory
What is the output of the following code? x = 5; y = 10; if x > y: print ('x is greater than y') else: print ('x is not greater than y')
- A. x is greater than y
- B. y is greater than x
- C. x is equal to y
- D. x is not greater than y
Brain break: Draw a picture of a giant banana dressed up as a cowboy, riding a unicorn!