list = [1, 2, -8, -2, 0]
print("The List of Elements are", list)
= min(list)
smallest list.remove(smallest)
= min(list)
second_smallest print("The Second Smallest Element in the List is",second_smallest)
print("The Removed(the first smallest number) element is",smallest)
The List of Elements are [1, 2, -8, -2, 0]
The Second Smallest Element in the List is -2
The Removed(the first smallest number) element is -8
= input("Enter the string")
string print("Before character exchange :",string)
= string[-1:] + string[1:-1] + string[:1]
result print("After character exchange :",result)
Enter the stringPythonLanguage
Before character exchange : PythonLanguage
After character exchange : eythonLanguagP
def longest_word(words):
= 0
longest_length = 0
longest_word for word in words:
if len(word) > longest_length:
= len(word)
longest_length = word
longest_word return longest_length, longest_word
= ["kiwi", "banana", "cherry", "watermelon"]
word_list = longest_word(word_list)
result_length, result_word print("Longest word length:", result_length)
print("Longest word:", result_word)
Longest word length: 10
Longest word: watermelon
=input("Enter the string:")
string=int(input("Enter the index of the character to remove:"))
n=string[n]
removed_character= string[:n] + string[n+1:]
modified_string print("Modified string after removing a character:",modified_string)
print("Removed character is",removed_character)
Enter the string:Python Programming
Enter the index of the character to remove:9
Modified string after removing a character: Python Prgramming
Removed character is o
output:
Key is present in the dictionary
Key is not present in the dictionary
# Answer 5
def is_key_present(dictionary,key):
if key in dictionary:
return ("Key is present in the dictionary")
else:
return ("Key is not present in the dictionary")
={1:10,2:20,3:30,4:40,5:50,6:60}
d= 5
key1 = 9
key2 = is_key_present(d,key1)
result1 = is_key_present(d,key2)
result2 print(result1)
print(result2)
Key is present in the dictionary
Key is not present in the dictionary