Jan-31-2018, 10:37 PM
(This post was last modified: Jan-31-2018, 10:38 PM by jmcatena91.)
OK, so this time I have a question about how to find the middle character/s. My instructions tell me for middle characters is
a. This operation will prompt the user for a choice between 'N' for number and 'S' for string
b. If the string has an odd number of characters
i. Determine the middle character of the string
ii. Display the single middle character to the user.
c. If the string has an even number of characters
i. Determine the middle characters of the string
ii. Display the two middle characters to the user.
I have everything done except this part. I can make it point to the middle characters for odd number numbers and strings but I dont want that, I want it to just display the letter/s and I have no clue where to start with 2 middle character strings. any info would be greatly appreciated!
The Middle Character is def MC and also commented with lable
a. This operation will prompt the user for a choice between 'N' for number and 'S' for string
b. If the string has an odd number of characters
i. Determine the middle character of the string
ii. Display the single middle character to the user.
c. If the string has an even number of characters
i. Determine the middle characters of the string
ii. Display the two middle characters to the user.
I have everything done except this part. I can make it point to the middle characters for odd number numbers and strings but I dont want that, I want it to just display the letter/s and I have no clue where to start with 2 middle character strings. any info would be greatly appreciated!
The Middle Character is def MC and also commented with lable
## multi line comment to easily display the menu a = ''' ************************** * menu * ************************** * CC - Character Count * * RV - Reverse * * M5 - Multiply by 5 * * MC - Middle Characters * ************************** * EX - Exit * ************************** ''' print(a) ## Creating the individual functions for each choice. ## Character Count def CC(): cc = input('Enter string: ') print("'" + cc + "' is", len(cc), "characters long") ## Reverse def RV(): rv = input('Enter string: ') print(rv[::-1]) ## Multiply by 5 def M5(): m5 = input('choose "N" for number or "S" for string: ') if m5.lower() not in ('n', 's'): print('That is not a valid option.') elif m5.lower() == 'n': num = input('Enter a number :') print(num, '* 5 equals: ', int(num) * 5) elif m5.lower() == 's': sstr = input('Enter a string: ') print(str(sstr) * 5) ## Middle-Character def MC(): mc = input('choose "N" for number or "S" for string: ') if mc.lower() not in ('n', 's'): print('That is not a valid option.') elif mc.lower() == 'n': ## This is used for odd only. text = input('Enter a number :') print(text) print('{0:^{1}}'.format('^',len(text))) elif mc.lower() == 's': ## This is used for odd only. text = input('Enter a string: ') print(text) print('{0:^{1}}'.format('^',len(text))) ## My function library MyFunctions = { 'cc': CC, 'rv': RV, 'm5': M5, 'mc': MC, } ## Function that actually calls the functions made at the beginning. def pick_a_function(): while True: func = input("Choose function 'CC', 'RV', 'M5', 'MC' or 'EX': ") if func.lower() == 'ex': print('Goodbye!') break elif func.lower() in MyFunctions: MyFunctions[func]() else: print('Invalid function, Try Again') pick_a_function()