code2pdf_679486b750c48
code2pdf_679486b750c48
"""exercise 1 and 2
x = "hello, world"
print(x)
name = "david"
age = 17
print("My name is", name, "and i am ", age, "years old")
one = 1
two = 2
three = one + two
print(three)
one = 1
two = 2
hello = "hello"
print(one + two , hello) #cannot out (one + two + hello) output>>> error because one and two are int and hello is a string
mystring = hello
myfloat = 10.0
myint = 20
#exercise 3 LISTS
thislist=['apple','banana','cherry']
print(thislist)
print(len(thislist)) # len function is used to determine how many items are there in the list
thislist=['apple','banana','cherry']
print(thislist)
print(type(thislist)) # data type
thislist= list(("apple:","banana","cherry"))
print(thislist) # list() -> list
thislist=['apple','banana','cherry']
thislist[:2]=['guava','watermelon'] # changin
print(thislist)
thislist=['apple','banana','cherry']
thislist[-1]
grocery_list=[]
def display_menu():
print("\nGrocery List Mnanager")
print("1. Add item")
print("2. Remove item")
print("3. View list")
print("4. Exit")
def add_item():
item=input("Enter the item to add")
grocery_list.append(item)
print(f"{item} has been added to the list.")
def remove_item():
item = input("Enter item to remove: ")
if item in grocery_list:
grocery_list.remove(item)
print(f"{item} has been removed from the list.")
else:
print(f"{item} is not in the list.")
def view_list():
if grocery_list:
print("\nYour grocery list:")
for idx, item in enumerate(grocery_list, start=1):
print(f"{idx}. {item}")
else:
print("Your grocery list is empty.")
while True:
display_menu()
choice = input("Choose an option (1-4): ")
if choice == "1":
add_item()
elif choice == "2":
remove_item()
elif choice == "3":
view_list()
elif choice == "4":
print("Exiting the Grocery List Manager. Goodbye!")
break
else:
print("Invalid choice. Please try again ")
fruits=["apple","banana","cherry"]
if "apple" in fruits: # in func helps to check if the data is present
print("yes, apple is a fruit")
else:
print('false')
#append()
thislist=['apple','banana','cherry']
thislist.append("orange")
print(thislist)
#insert ()
thislist=['apple','banana','cherry']
thislist.insert(2,"watermelon")
print(thislist)
#extend list
list=[1,2,3,4]
list.extend([5,6,7])
print(list)
#remove()
list = ["apple","banana","cherry"]
list.remove("banana")
print(list)