Search the courses, subjects, tracks, games and features, or jump straight to a page.
Learn it your way
A short class with Sarah and her students. The other ways are under More.
Sign up free to listen. Transcripts are free to read.
Today, we're going to enhance our Python skills by writing a program that prints your name and age. Can anyone tell me what function we can use for printing in Python?
Is it the print() function?
Exactly! The print() function outputs text to the console. Let's write a simple program: print('Your Name, Your Age'). Now, who's ready to try it with their own values?
If I wanted to print my name, how would that work?
Great question! Just replace 'Your Name' with your name, like this: print('Alice, 20'). Why don't you give it a shot?
In this session, we will learn how to take user input. Who can tell me the function we use to get input from a user?
I think it's input()?
Correct! The input() function lets us capture user data. Now we'll write a program to add two numbers. Can anyone outline the steps to achieve this?
First, we can ask for the first number, then the second, and finally we need to print their sum.
Well done! Remember to convert the input to integers. So, after collecting the input, use int() to convert, like this: int(input('Enter the first number: ')). Let's write the program together.
Now, let's create a program that checks if a number is even or odd. Can someone remind me how we can use conditional statements in Python?
We'll use if and else statements!
Exactly! We can check the remainder when dividing by 2. If it's 0, the number is even. We'll write this as if number % 2 == 0:. Now, who wants to write this logic in the code?
I can do it! So we ask for a number and then check it, right?
Perfect! Let's code this together and ensure we print whether the number is even or odd.
Next up is using loops! Who here is familiar with the for loop?
We can use it to repeat actions, right? Like printing numbers?
Exactly! Let's write a for loop that prints numbers from 1 to 10. What does our loop might look like?
I think we should use for i in range(1, 11): and then print i.
You're spot on! Let's implement that code, and I want everyone to run it and see the numbers printed.
Finally, let’s talk about lists. How do we define a list of fruits in Python?
We can use square brackets, like fruits = ['apple', 'banana', 'cherry'].
Exactly! And how can we print the third fruit from this list?
Use print(fruits[2]) since the index starts at 0!
That's correct! Let's code this up and see the output together.
Use the print() function to display information.
The input() function captures input from the user.
Use conditionals to determine if a number is even or odd.
Use for loops to iterate through sequences.
Create ordered collections of items using lists.
Print to show, Input to go, Even for balance, Odd to throw!
Once there was a programmer who could print the name of every fruit he ate. With print(), his story began, and he eagerly awaited the user's input to add to his list!
PIES - Print, Input, Even, Sum - to remember the basics of Python tasks.
LIMP - Loops, Input, Module, Print - to remember key concepts in Python.
Term
What function is used to output text?
Click to flip
Term
How do you capture user input?
Click to flip
Term
What statement is used for conditions?
Click to flip
Term
What loop structure is used to repeat actions?
Click to flip
Term
How are lists defined?
Click to flip
A built-in function in Python that outputs text to the console.
A built-in function that allows user input from the console.
A conditional statement that executes a block of code if its condition is true.
A control structure for iterating over a sequence (like a list or a range).
An ordered collection of items (mutable) in Python, defined using square brackets.
This section presents a set of practice programs designed to enhance understanding of fundamental Python concepts.
Practice programs are essential for reinforcing learning in Python. This section includes exercises focused on printing output, taking user input, and working with loops and lists, aimed at solidifying the expertise of beginners in Python programming.
In the Practice Programs section, readers engage with a variety of programming exercises to reinforce the concepts introduced earlier in the chapter about Python. Each program is designed to be simple yet effective, covering fundamental skills such as printing output, manipulating variables, and using control structures like loops and conditionals. The exercises include:
print() function.These exercises collectively help students practice their coding skills while instilling confidence in their ability to write simple programs.