try:
file = open("a_file.txt") # first error
a_dictionary = {"key": "value"}
print(a_dictionary["non_existent_key"]) # second error
except FileNotFoundError:
file= open("a_file.txt","w")
file.write("Something")
except KeyError as error_message:
print(f"The key {error_message} does not exist.")
else:
content = file.read()
print(content)
finally:
file.close()
print("file was closed!")
height = float(input("Height: "))
weight = int(input("Weight: "))
if height > 3:
raise ValueError("Human Height should not be over 3 meters.")
bmi = weight / height ** 2
print(bmi)
fruits = ["Apple", "Pear", "Orange"]
def make_pie(index):
try:
fruit = fruits[index]
print(fruit + " pie")
except IndexError:
print("There is no index exist in list.")
else:
print(fruit+"pie")
make_pie(4)
facebook_posts = [
{'Likes': 21, 'Comments': 2},
{'Likes': 13, 'Comments': 2, 'Shares': 1},
{'Likes': 33, 'Comments': 8, 'Shares': 3},
{'Comments': 4, 'Shares': 2},
{'Comments': 1, 'Shares': 1},
{'Likes': 19, 'Comments': 3}
]
total_likes = 0
for post in facebook_posts:
try:
total_likes = total_likes + post['Likes']
except KeyError:
pass # or total_likes += 0
print(total_likes)
import pandas as pd
data = pd.read_csv("nato_phonetic_alphabet.csv")
phonetic_dict = {row.letter:row.code for (index, row) in data.iterrows()}
def generate_phonetic():
word = input("Enter a word: ").upper()
try:
output_list = [phonetic_dict[letter] for letter in word]
except KeyError:
print("Sorry, only letters in the alphabet please.")
generate_phonetic()
else:
print(output_list)
generate_phonetic()
If you want to be discreet while exploring the red-light districts in Bandra West Escorts you can hire an Bandra Escorts. The city is home to some of the largest red-light districts in Asia, including.
All the VIP AIIMS Call Girls available near the all NCR 5 Star to 3 star hotels. You just need to call to our girls on the given below number and these are the premium escorts who will give you premium feeling on the bed.
I'm Ruhi and I'm managing the https://www.adelhiescort.com/location/noida-escorts.html Organization near Entryway of Indian Lodgings, Consistently the clients interest for the free transport of the females who are working in my association.