YDP Python Lessons

YDP Python Lesson Exercises

Module 2 Practice Exercises

Data Types, Variables, Basic Input-Output Operations, Basic Operators

Exercise 1: Variable Declaration and Basic Operators

# Declare two variables 'a' and 'b' and assign values to them.
# Perform basic arithmetic operations (addition, subtraction, multiplication, division, and modulus) on these variables.
# Print the results.

a = 10
b = 5

# Add your code here to perform operations and print results

Explanation: This exercise covers the concept of declaring variables, assigning values to them, and performing basic arithmetic operations using operators like '+', '-', '*', '/', and '%'.

Exercise 2: User Input and Output

# Prompt the user to enter their name and age.
# Read the input values and store them in variables.
# Display a message that includes the user's name and age.

# Add your code here to prompt for input and display the message

Explanation: This exercise focuses on using input() to get user input and print() to display output. It also involves variable assignment.

Exercise 3: String Manipulation

# Create a string variable containing your full name.
# Use string slicing to display your first name and last name separately.
# Display the length of your full name.

# Add your code here to manipulate the string and display its length

Explanation: This exercise focuses on string data types, string slicing, and using the len() function to find the length of a string.

Exercise 4: Variable Types and Type Conversion

# Declare a variable 'num1' with an integer value and 'num2' with a float value.
# Perform type conversion to convert 'num1' to a float and 'num2' to an integer.
# Display the results and their types.

num1 = 10
num2 = 5.5

# Add your code here to perform type conversion and display results

Explanation: This exercise introduces variable types (integers and floats) and demonstrates type conversion between them.

Exercise 5: String Manipulation

# Create a string variable containing your full name.
# Use string slicing to display your first name and last name separately.
# Display the length of your full name.

# Add your code here to manipulate the string and display its length

Explanation: This exercise focuses on string data types, string slicing, and using the len() function to find the length of a string.

Exercise 6: Variable Types and Type Conversion

# Declare a variable 'num1' with an integer value and 'num2' with a float value.
# Perform type conversion to convert 'num1' to a float and 'num2' to an integer.
# Display the results and their types.

num1 = 10
num2 = 5.5

# Add your code here to perform type conversion and display results


	

Explanation: This exercise introduces variable types (integers and floats) and demonstrates type conversion between them.

Submit your exercise files below

Submit