Suppose you have $100, which you can invest with a 10% return each year. Add code to calculate how much money you end up with after 7 years, and print the result.
# Addition, subtraction
print(5 + 5)
print(5 - 5)
# Multiplication, division, modulo, and exponentiation
print(3 * 5)
print(10 / 2)
print(18 % 7)
print(4 ** 2)
# How much is your $100 worth after 7 years?
print(100 * (1.1) ** 7)
Write a function to calculate bmi, it should be able to convert numbers into float.
def bmi_cal():
x = float(input("what is your height in meters"))
y = float(input("what is your weight in kg?"))
bmi = y/x ** 2
print(bmi)
bmi_cal()
Create a conditional sublist of dictionary.
# Create a dictionary with some key-value pairs
my_dict = {"key1": "value1", "key2": "value2", "key3": "value3"}
# Get a sublist of the dictionary containing key-value pairs for "key1" and "key2"
sublist = {key: value for key, value in my_dict.items() if key in ["key1", "key2"]}
# Print each key and value in the sublist
for key, value in sublist.items():
print(f"Key: {key}, Value: {value}")
No comments:
Post a Comment