Question

In: Computer Science

Write a Python program that has the user enter their name.   Using the user's name calculate...

Write a Python program that has the user enter their name.   Using the user's name calculate the following:

1. How many letters are in the user's name?

2. Print the user's name in REVERSE both in capital letters and lowercase letters

3. Print the ASCII value for each letter of the user's name.

4. Print the SUM of all of the letters of the user's name (add each letter from #3)

Solutions

Expert Solution

1.

The line of code from which the length of the user name is computed in python is provided below:

#Compute the length of the entered user name.

print('Length of the user name : ' , len(user_name))

2.

The line of code to reverse the upper case and the lower case letters is provided below:

#Convert the user name in lower and the upper case.

username_lower = user_name.lower()

username_upper = user_name.upper()

#Display the reversed string in upper and lower both case.

print('Reversed letter in lower case :', username_lower[::-1])

print('Reversed letter in upper case :', username_upper[::-1])

3.

The line that display the ASCII values of the user’s name is provided below:

#Display the ASCII values of the entered user name.

for i in user_name:

    print('ASCII value of ', i ,':' ,ord(i))

4.

The line to sum up the letters of the user’s name is provided below:

#Display the sum of the letters of the entered user name.

print('Sum of letters of the user name : ',sum(map(ord, user_name)))

The complete code of the above four parts in python is provided below:

Screenshot of the code:

Sample Output:

Code To Copy:

#Run the code in python version 3.x.

#Indent the code as per the above screenshot of the code. Otherwise it may give error.

#Prompt the user to enter the user's name.

user_name = input('Enter the user name : ')

#SOLUTION FOR PART 1.

#Compute the length of the entered user name.

print('Length of the user name : ' , len(user_name))

#SOLUTION FOR PART 2.

#Convert the user name in lower and the upper case.

username_lower = user_name.lower()

username_upper = user_name.upper()

#Display the reversed string in upper and lower both case.

print('Reversed letter in lower case :', username_lower[::-1])

print('Reversed letter in upper case :', username_upper[::-1])

#SOLUTION FOR PART 3.

#Display the ASCII values of the entered user name.

for i in user_name:

    print('ASCII value of ', i ,':' ,ord(i))

#SOLUTION FOR PART 4.

#Display the sum of the letters of the entered user name.

print('Sum of letters of the user name : ',sum(map(ord, user_name)))


Related Solutions

Write a Python program that asks the user to enter a student's name and 8 numeric...
Write a Python program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name will be a local variable. The program should display a letter grade for each score, and the average test score, along with the student's name. Write the following functions in the program: calc_average - this function should accept 8 test scores as arguments and return the average of the scores per student determine_grade -...
PYTHON Write a program that asks the user to enter a student's name and 8 numeric...
PYTHON Write a program that asks the user to enter a student's name and 8 numeric assignment scores (out of 100 for each assignment). The program should output the student's name, a letter grade for each assignment score, and a cumulative average for all the assignments. Please note, there are 12 students in the class so your program will need to be able to either accept data for 12 students or loop 12 times in order to process all the...
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
C++ : Write a program that creates a login name for a user, given the user's...
C++ : Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input. Output the login name, which is made up of the first five letters of the last name, followed by the first letter of the first name, and then the last two digits of the number (use the % operator). If the last name has less than five letters, then use all letters of the...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter his/her favorite English saying, then counts the number of vowels in that (note that the user may type the saying using any combination of upper or lower case letters). Example: Enter your favorite English saying: Actions speak LOUDER than words. Number of wovels: 10
USING PYTHON. Thank you in advance Write a program that allows the user to enter a...
USING PYTHON. Thank you in advance Write a program that allows the user to enter a series of string values into a list. When the user enters the string ‘done’, stop prompting for values. Once the user is done entering strings, create a new list containing a palindrome by combining the original list with the content of the original list in a reversed order. Sample interaction: Enter string: My Enter string: name Enter string: is Enter string: Sue Enter string:...
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Write a Python program using functions and mainline logic which prompts the user to enter a...
Write a Python program using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a file. It should then display the following data to back to the user: The list of integers The lowest number in the list The highest number in the list The total sum of all the numbers in the list The average number in the list At a minimum, the numbers should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT