0% found this document useful (0 votes)
3 views

Python_Homework

The document outlines a Python homework assignment focused on practicing variables, functions, string formatting, and list methods. It includes specific tasks such as creating variables of different types, user input handling, string manipulation, and list operations. Additional resources for further learning are also provided.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python_Homework

The document outlines a Python homework assignment focused on practicing variables, functions, string formatting, and list methods. It includes specific tasks such as creating variables of different types, user input handling, string manipulation, and list operations. Additional resources for further learning are also provided.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Homework

Homework Tasks

This homework will help you practice the topics we covered in the last lesson:

- Variables and their types: int, float, bool, string, and list.

- Basic functions: print(), input(), type(), int(), str().

- String formatting and methods.

- List methods.

Tasks:

1. Create variables of each type (int, float, bool, string, list). Print their types using the type() function.

2. Write a program that asks the user to input their age using input(). Convert the input to an integer using

int() and print a message: 'You are X years old!', where X is the user's age.

3. Practice string formatting: Create a variable with your name and age. Print the sentence: 'My name is

[Name] and I am [Age] years old.' using formatted strings.

4. Write a program to demonstrate at least three string methods (e.g., upper(), lower(), replace()).

5. Create a list of your favorite fruits and print the list. Add a new fruit to the list, remove one, and print the

updated list.

6. Create a program that accepts a list of numbers (as input, comma-separated) from the user, and then

converts it into a list. Print the largest and smallest number in the list.

7. Explore the slicing of strings and lists: Print the first 3 characters of a string and the last 2 elements of a

list.

Additional Resources:

For more information about variables and their types, you can refer to the following article:

Page 1
Python Homework

https://realpython.com/python-variables/

Practice string and list methods here:

https://docs.python.org/3/tutorial/datastructures.html

https://realpython.com/python-strings/

Page 2

You might also like