. Execute the following string operations by writing an efficient python program by using switch case.
1. Convert the input string into upper case.
2. Convert the input string into lower case.
3. Check whether all the characters of the input string are in upper case.
4. Check whether all the characters of the input string are in lower case.
5. Replace the string "INTELLIgence" by "Neural Network".
6. Check whether the given string starts with "T".
7. Check whether the given string ends with "e".
8. Convert the first letter of the input string into capital letter.
9. Convert the lower-case characters to upper case and vice versa.
INPUT:" aRTificial INTELLIgence"
Answers
Answer:
Program :-
string = input("Enter a string: ")
print("1. convert the input string into upper case.")
print("2. convert the input string into lower case.")
print("3. Check whether all the character of the input string are in upper case.")
print("4. Check whether all the character of the input string are in lower case.")
print("5. Replace the string 'INTELLIgence' by 'Neural Network'.")
print("6. Check whether the given string starts with 'T'.")
print("7. Check whether the given string ends with 'e'.")
print("8. Convert the first letter of the input string into capital letter.")
print("9. Convert the lower-case characters to upper case and vice versa.")
print("10. Exit")
print("-" * 20)
def switch(string,option) :
match option :
case 1 :
print(string.upper())
case 2 :
print(string.lower())
case 3 :
print(string.isupper())
case 4 :
print(string.islower())
case 5 :
print(string.replace("INTELLIgence","Neural Network"))
case 6 :
print(string.startswith("T"))
case 7 :
print(string.endswith("e"))
case 8 :
print(string.capitalize())
case 9 :
print(string.swapcase())
while True :
option = int(input("Choose any option: "))
if option == 10 :
print("...Program Terminated...")
break
switch(string,option)
Output:-
Enter a string: aRTificial INTELLIgence
1. convert the input string into upper case.
2. convert the input string into lower case.
3. Check whether all the character of the input string are in upper case.
4. Check whether all the character of the input string are in lower case.
5. Replace the string 'INTELLIgence' by 'Neural Network'.
6. Check whether the given string starts with 'T'.
7. Check whether the given string ends with 'e'.
8. Convert the first letter of the input string into capital letter.
9. Convert the lower-case characters to upper case and vice versa.
10. Exit
--------------------
Choose any option: 1
ARTIFICIAL INTELLIGENCE
Choose any option: 2
artificial intelligence
Choose any option: 3
False
Choose any option: 4
False
Choose any option: 5
aRTificial Neural Network
Choose any option: 6
False
Choose any option: 7
True
Choose any option: 8
Artificial intelligence
Choose any option: 9
ArtIFICIAL intelliGENCE
Choose any option: 9
ArtIFICIAL intelliGENCE
Choose any option: 11
Choose any option: 10
...Program Terminated...
Explanation:
match-case is similar to switch-case in C/C++/Java.
Note:- match-case statements was introduced in python 3.10 and work only in python version 3.10 and above.
Answer:
Put this string in the box: artificial intelligence.
1. make the input string all capital letters.
2. lowercase the input string's characters.
3. Verify that the input string's characters are all capitalised.
4. Verify that all of the input string's characters are lowercase.
5. Change "INTELLIgence" to "Neural Network" in the string.
6. Verify if the given text begins with "T."
7. Verify whether the string in question ends in "e."
8. Change the input string's first letter to a capital letter.
9. Change the case of the characters, from lowercase to uppercase and vice versa.
10. Exit
——————————
Pick any of the following: 1
AUTHENTIC INTELLIGENCE
Select any of the following: 2
synthetic intelligence
Pick any of the following: 3
False
Pick any of the following: 4
False
any of the following: 5
Synthetic Neural Network
Select any of the following: 6
False
Select any of the following: 7
True
Pick any of these: 8
synthetic intelligence
Select any of the following: 9
Synthetic intelligence
Select any of the following: 9
Synthetic intelligence
Select any of the following:
Elect any alternative: 10
Program Has Ended...
#SPJ2