MTH202 Worksheet 1¶
Problem 1¶
Define three string variables:
nameto store your first name,surnameto store your last name,idto 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
Fruitswith itemsbanana,mango, andwatermelon. - Create a list
Vegetableswith itemscucumberandcabbage. - Create a list
Meatswith itemschicken,porkandbeef. - Create a list
Basketcontaining 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']