Aim: To create, concatenate, and print a string and access a sub-string from a given string.
Algorithm:
Part 1: Create, Concatenate, and Print String
Step 1: Start
Step 2: Prompt the user to enter the first string.
Step 3: Store the first string in variable string1.
Step 4: Prompt the user to enter the second string.
Step 5: Store the second string in variable string2.
Step 6: Concatenate string1 and string2 using the + operator and store in concatenated_string.
Step 7: Display the value of concatenated_string.
Step 8: Prompt the user to enter an additional string.
Step 9: Append the additional string to concatenated_string using +=.
Step 10: Display the updated concatenated_string.
Step 11: Stop
Part 2: Access Sub-strings (Slicing)
Step 1: Prompt the user to enter a sample string.
Step 2: Store it in variable sample_string.
Step 3: Access the first 5 characters: sample_string[:5].
Step 4: Access characters from index 5 to the end: sample_string[5:].
Step 5: Access characters from index 2 to 6: sample_string[2:6].
Step 6: Access the last 3 characters using negative indexing: sample_string[-3:].
Step 7: Access every second character: sample_string[::2].
Step 8: Display all the accessed substrings.
Step 10: Stop
Credits: Code with navaf