Add Lab 8

This commit is contained in:
sys_32
2023-10-20 17:21:34 +00:00
committed by GitHub
parent 62c9aeedda
commit f4f39cd24a
4 changed files with 123 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
# Edwin Hui
red = "A Red Fox "
blue = "Chased a Blue Mouse "
green = "Across a Green Meadow."
print(red + blue + green)
# Defining the varibles red, blue and greenm and printing them out.
print("----------------")
complete = red + blue + green
print(complete)
# defining the varible complete as the combination of red, blue and green and printing it out.
print("----------------")
print(complete.lower())
print(complete)
# prints out var complete in all lowercasem then prints it out the original to prove that the varible has not been modified.
print("----------------")
print(complete.upper())
print(complete)
print("----------------")
print(complete[19])
# prints index 19 in var complete.
print("----------------")
print(complete[19:23])
# prints index 19-23 in var complete.
print("----------------")
print(len(complete))
# prints the count of characters in var complete.
print("----------------")
print(complete.isnumeric())
# checks if var complete can be converted to numeric and prints true or false
print("----------------")
convvar = "1938"
print(convvar.isnumeric())
# define convar as a numeric string and print true or false if it can be converted to numeric.

View File

@@ -0,0 +1,38 @@
# Edwin Hui
my_num_list = [3, 6, 4, 83, 2, 7, 2, 17, 4, 9, 0, 44, 2]
print("----------------")
print(my_num_list[3])
print("----------------")
my_num_list.append(8)
print(my_num_list)
# adds 8 to the end of the list, then prints the list
print("----------------")
i = 33
my_num_list.insert(4, i)
print(my_num_list)
# inserts 33 at index 4, then prints the list
print("----------------")
print(my_num_list.count(2))
print("----------------")
my_num_list.sort()
print(my_num_list)
# sorts the list, then prints the list
print("----------------")
print(len(my_num_list))
print("----------------")
my_num_list.pop()
print(my_num_list)
my_num_list.pop()
my_num_list.pop()
my_num_list.pop()
# removes the last item from the list, then prints the list, then removes 3 more
print("----------------")
print(my_num_list)
print("----------------")
print(len(my_num_list))
count = 0
while count < len(my_num_list):
print(my_num_list[count])
count += 1
# prints the list one item per line

View File

@@ -0,0 +1,22 @@
# Edwin Hui
my_char_list = ['a', 'b', 'a', 'c', 'd', 'a', 'd', 'z', 'r', 'a']
print("----------------")
print(len(my_char_list))
print("----------------")
print(my_char_list.index('d'))
# prints the index position of "d"
print("----------------")
my_char_list.insert(3, 'a')
print(my_char_list)
# inserts "a" at index 3
print("----------------")
print(len(my_char_list))
print("----------------")
print(my_char_list.count('a'))
# counts the ammount of "a" in the list
print("----------------")
count = 0
while count < len(my_char_list):
print(my_char_list[count])
count += 1
# prints the list one item per line

View File

@@ -0,0 +1,30 @@
# Edwin Hui
num_list = [34, 42, 99, 1301, 1, 78, 314, 818, 777]
print(num_list)
print("----------------")
add = 0
count = 0
while count < len(num_list):
print(num_list[count], end = " ")
add = add + num_list[count]
count += 1
# prints the list all in one line, while adding the list items together
print()
print("total:", add)
num_list.sort()
print("largest number:", num_list[8])
# sorts the list, then prints last item in the list (which is the largest number)
print("----------------")
num_list = [3, 7, 999, 1981, 1066, -4086, 33]
print(num_list)
add = 0
count = 0
while count < len(num_list):
print(num_list[count], end = " ")
add = add + num_list[count]
count += 1
print()
print("total:", add)
num_list.sort()
print("largest number:", num_list[6])
# repeats above but for a different list