# This is program with dictionary
# Create a dictionary to store information about a person
person = {
"first_name": "Abdullah",
"last_name": "Khanani",
"age": 15,
"city": "Los Angeles"
}
# Accessing values in the dictionary
print("First Name:", person["first_name"])
print("Last Name:", person["last_name"])
print("Age:", person["age"])
print("City:", person["city"])
# Modifying values in the dictionary
person["city"] = "San Diego" # Update the city
# Adding a new key-value pair to the dictionary
person["country"] = "USA"
# Accessing the updated values
print("Updated City:", person["city"])
print("Country:", person["country"])
# Deleting a key-value pair from the dictionary
del person["country"]
# Checking if a key exists in the dictionary
if "country" in person:
print("Country:", person["country"]) # This will not be executed because "country" was deleted
else:
print("Country not found.")
if "city" in person:
print("City:", person["city"]) # This will not be executed because "country" was deleted
else:
print("City not found.")
First Name: Abdullah
Last Name: Khanani
Age: 15
City: Los Angeles
Updated City: San Diego
Country: USA
Country not found.
City: San Diego
The area of the rectangle with length 6.0 and width 9.0 is 54.0 square units.
Hello, Sergi! Welcome to the interactive program.
You are a minor.
# Program with List
# Create an empty list
numbers = []
# Get the number of elements in the list from the user
num_elements = int(input("Enter the number of elements in the list: "))
# Get the elements from the user and add them to the list
for i in range(num_elements):
element = float(input(f"Enter Number {i + 1}: "))
numbers.append(element)
# Display the list
print("List of numbers:", numbers)
# Calculate and display the sum of the numbers
total = sum(numbers)
print("Sum of numbers:", total)
# Calculate and display the average of the numbers
average = total / len(numbers)
print("Average of numbers:", average)
# Find and display the maximum and minimum values in the list
maximum = max(numbers)
minimum = min(numbers)
print("Maximum value:", maximum)
print("Minimum value:", minimum)
List of numbers: [20.0, 9.0, 9.0, 7.0]
Sum of numbers: 45.0
Average of numbers: 11.25
Maximum value: 20.0
Minimum value: 7.0
# Program with a Function to perform mathematical and/or a statistical calculations
import statistics
def calculate_statistics(numbers):
# Calculate mean
mean = sum(numbers) / len(numbers)
# Calculate median
median = statistics.median(numbers)
# Calculate standard deviation
std_deviation = statistics.stdev(numbers)
return mean, median, std_deviation
# Example list of numbers
data = [15, 45, 69, 88, 25, 57, 73, 31, 99]
# Calculate statistics using the function
mean, median, std_deviation = calculate_statistics(data)
# Display the results
print("Data:", data)
print("Mean:", mean)
print("Median:", median)
print("Standard Deviation:", std_deviation)
Data: (15, 45, 69, 88, 25, 57, 73, 31, 99)
Mean: 55.77777777777778
Median: 57
Standard Deviation: 28.981795052143415
The square of 4.0 is 16.0.