def area_of_circle(r):
area = 3.14 * r * r
print(area)
area_of_circle(5) # This line calls the function
78.5
shopping = ["apples", "bread"]
def delete_from_list(item):
shopping.append(item)
print(shopping)
delete_from_list("ketchup")
['apples', 'bread', 'ketchup']
shopping = ["apples", "bread", "ketchup"]
def delete_from_list(item):
shopping.pop(item)
print(shopping)
delete_from_list(0)
['bread', 'ketchup']
count = 0
def increment_counter():
global count
count += 1
increment_counter()
increment_counter()
print(count)
2
def linear_search(search_list, value):
flag = False
for index in range(0, len(search_list)):
if search_list[index] == value:
flag = True
break
if flag == True:
print("item found in list")
else:
print("value not found")
my_list = [3, 7, 1, 9, 2]
target_value = 7
linear_search(my_list, target_value)
item found in list
def reverse_list(data):
print(data.reverse())
my_list = [1, 2, 3, 4, 5]
reverse_list(my_list)
[5, 4, 3, 2, 1]
def find_vowels(text):
string = ""
vowels = "aeiou"
for char in text:
if char.lower() in vowels:
string += char
print(string)
find_vowels("Hello, World!")
eoo
def display_progress_bar(progress):
bar_length = 5
completed = int(progress * bar_length)
print(f'[{"#" * completed}{" " * (bar_length - completed)}] {str(int(progress * 100))}%')
# Example usage
for i in range(5):
display_progress_bar(i/5)
[ ] 0%
[# ] 20%
[## ] 40%
[### ] 60%
[#### ] 80%