MTH202 Worksheet 1¶

Problem 1¶

Define three string variables:

  • name to store your first name,
  • surname to store your last name,
  • id to store your student ID.
In [2]:
name = "Parin"
surname = "Chaipunya"
id = "52213005"

Problem 2¶

Define a list L that consists of three items: name, surname, and id.

In [3]:
L = [name, surname, id]

Problem 3¶

Use the f-string and access the strings from the list L to display your fisrt name, last name, and student id using the following sample format.

First name: Parin
Last name: Chaipunya
Student ID: 52213005
In [4]:
print(f"First name: {name}")
print(f"Last name: {surname}")
print(f"Student ID: {id}")
First name: Parin
Last name: Chaipunya
Student ID: 52213005

Problem 4¶

  • Create a list Fruits with items banana, mango, and watermelon.
  • Create a list Vegetables with items cucumber and cabbage.
  • Create a list Meats with items chicken, pork and beef.
  • Create a list Basket containing all the items above by joining the above lists.
  • From Basket, use list slicing and print everything except the vegetables. (Hint: You may need to use + to join the two slices.)
In [5]:
Fruits = ["banana", "mango", "watermelon"]
Vegetables = ["cucumber", "cabbage"]
Meats = ["chicken", "pork", "beef"]
Basket = Fruits + Vegetables + Meats
print(Basket[0:3]+Basket[5:])
['banana', 'mango', 'watermelon', 'chicken', 'pork', 'beef']