Answered You can hire a professional tutor to get the answer.
Part A In Python, there are two main rules for naming variables.
Strings
This assignment focuses on indexing, slicing, and iterating over strings as well as Python’s standard string functions.
Part AIn Python, there are two main rules for naming variables.
- The first character cannot be a number.
- Only letters, numbers, and the underscore character are allowed.
Write a program that prompts users to enter a potential variable name and tells them whether or not it is valid. Your program should consist of two functions. The first should take one argument—the potential variable name, validate the name, and return Boolean Trueif it is valid or False if it is not. The second, a main() function, should get input from the user, call the validator function and print “This is a valid variable name” or “This is not a valid variable name.”
Users should repeatedly be prompted to enter another variable name until they enter “done.” Here is a demo of the program.
Enter your Python variable name: high_tempThis is a valid variable name.Enter your Python variable name or "done": highTemp2This is a valid variable name.Enter your Python variable name or "done": 2_high_tempThis is not a valid variable name.Your final program should work like this.
Enter your name: GuidoYour personality number is: 11Your personality associations are:add_lettersa word to scramble (String) and a number of letters (integer)# processing: adds a number of random letters (A-Z; a-z) after each letter in the supplied word. for example, if word="cat" and num=1 we could generate any of the following:cZaQtRcwaRtscEaett# if word="cat" and num=2 we could generate any of the following:cRtaHFtuicnnaNYtjnczAaAitym#returns the newly generated worddef add_letters(word, num):# function code goes here!Sample Program
# define original wordoriginal = "Hello!"# loop to demonstrate the functionfor num in range(1, 5):# scramble the word using 'num' extra charactersscrambled = add_letters(original, num)# outputprint("Adding", num, "random characters to", original, ". . .", scrambled)Sample Output
Adding 1 random characters to Hello! . . . HdeulHlHom!tAdding 2 random characters to Hello! . . . HTLedklFNljioMH!biAdding 3 random characters to Hello! . . . HHHZeZrflqSflzOiosNU!jBkremove_lettersa word to unscramble (String) and the number of characters to remove (integer)# processing: the function starts at the first position in the supplied word and keeps it.it then removes "num" characters from the word. the process is repeated againif the word contains additional characters - the next character is keptand "num" more characters are removed. For example, if word="cZaYtU" andnum=1 the function will generate the following:cat (keeping character 0, removing character 1, keeping character 2, removingcharacter 3, keeping character 4, removing character 5)#returns the newly unscrambed worddef remove_letters(word, num):# function code goes here!Sample Program
word1 = "HdeulHlHom!t"word2 = "HTLedklFNljioMH!bi"word3 = "HHHZeZrflqSflzOiosNU!jBk"word4 = "HFtRKeivFllRNlUlGTaooYwoH!JpXL"unscrambled1 = remove_letters(word1, 1)print("Removing 1 characer from", word1, ". . .", unscrambled1)unscrambled2 = remove_letters(word2, 2)print("Removing 2 characers from", word2, ". . .", unscrambled2)unscrambled3 = remove_letters(word3, 3)print("Removing 3 characers from", word3, ". . .", unscrambled3)unscrambled4 = remove_letters(word4, 4)print("Removing 4 characers from", word4, ". . .", unscrambled4)Sample Output
Removing 1 characer from HdeulHlHom!t . . . Hello!Removing 2 characers from HTLedklFNljioMH!bi . . . Hello!Removing 3 characers from HHHZeZrflqSflzOiosNU!jBk . . . Hello!shift_charactersa word (String) and a number of characters to shift (integer)# processing: shifts each character in the supplied word to another position in the ASCIItable. the new position is dictated by the supplied integer. for example,if word = "apple" and num=1 the newly generated word would be:#bqqmf#because we added +1 to each character. if we were to call the function withword = "bqqmf" and num=-1 the newly generated word would be:apple#because we added -1 to each character, which shifted each character down byone position on the ASCII table.#returns the newly generated worddef shift_characters(word, num):# function code goes here!Sample Program
word1 = "apple"newword1 = shift_characters(word1, 1)print(word1, "shifted by +1 is", newword1)unscrambled1 = shift_characters(newword1, -1)print(newword1, "shifted by -1 is", unscrambled1)word2 = "Pears are yummy!"newword2 = shift_characters(word2, 2)print(word2, "shifted by +2 is", newword2)unscrambled2 = shift_characters(newword2, -2)print(newword2, "shifted by -2 is", unscrambled2)Sample Output
apple shifted by +1 is bqqmfbqqmf shifted by -1 is applePears are yummy! shifted by +2 is Rgctu"ctg"{woo{#Here’s a sample running of the program:
(e)ncode, (d)ecode or (q)uit: eEnter a number between 1 and 5: 1Enter a phrase to encode: appleYour encoded word is: boqDqfmsfz(e)ncode, (d)ecode or (q)uit: dEnter a number between 1 and 5: 1Enter a phrase to decode: boqDqfmsfzYour decoded word is: apple(e)ncode, (d)ecode or (q)uit: eEnter a number between 1 and 5: 2Enter a phrase to encode: Hello, World!! :)Your encoded word is: JHmgn{nNYnukqFR.Fq"vEYOqYFt[n{lf|Y#mJ#kr"UT<cE+og(e)ncode, (d)ecode or (q)uit: dEnter a number between 1 and 5: 2Enter a phrase to decode: JHmgn{nNYnukqFR.Fq"vEYOqYFt[n{lf|Y#mJ#kr"UT<cE+ogYour decoded word is: Hello, World!! :)(e)ncode, (d)ecode or (q)uit: q