Ms. Terkper's Digital Classroom

Introduction to Python: Basics #1

Introduction to Python - Basics #1

Python is a high-level, beginner-friendly programming language used in robotics, automation, game development, and artificial intelligence. It is known for its simple and readable syntax, making it a great first language for learning programming.

1. Printing Output in Python

One of the first things you'll do in Python is display text on the screen using the print() function.

        
print("Hello, World!")
        
    

Output:

        
Hello, World!
        
    

2. Taking User Input

Python allows users to enter data using the input() function:

        
name = input("Enter your name: ")
print("Hello, " + name + "!")
        
    

Example Output: If the user types Hannah, the output will be:

        
Hello, Hannah!
        
    

3. Variables and Data Types

In Python, a variable is used to store values, such as numbers or text:

        
age = 15
height = 5.7
name = "Hannah"
        
    

Common Data Types:

4. Type Conversion

When using input(), Python always treats the input as a string. To use numbers, we need to convert the type:

        
age = input("Enter your age: ")  # Input is stored as a string
age = int(age)  # Convert to integer
print("Next year, you will be " + str(age + 1) + " years old!")
        
    

Now that you've learned the basics, try answering the questions below! 👇

1. What will the following code output?

        
print("Hello, World!")
        
    

2. Which function allows a user to enter input in Python?

3. Which of the following correctly stores user input in a variable?

4. What will the following code output?

        
name = "Alex"
print(name)
        
    

5. What data type is stored in the variable: user_age?

6. What symbol is used for writing comments in Python?

7. Which of the following is a valid variable name in Python?

8. How do you convert user input to an integer in Python?

9. What happens if you try to add an integer and a string in Python?

10. What will happen if you forget parentheses in `print "Hello"`?