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 -...
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
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...
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...
Using Python Write a program that does the following in order: 1.     Asks the user to enter...
Using Python Write a program that does the following in order: 1.     Asks the user to enter a name 2.     Asks the user to enter a number “gross income” 3.     Asks the user to enter a number “state tax rate” 4.     Calculates the “Federal Tax”, “FICA tax” and “State tax” 5.     Calculates the “estimated tax” and round the value to 2 decimal places 6.     Prints values for “name”, “gross income” and “estimated tax” The program should contain three additional variables to store the Federal tax, FICA...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Write a program using the switch statement to calculate geometric quantities. Prompt the user to enter...
Write a program using the switch statement to calculate geometric quantities. Prompt the user to enter a radius. Then present a menu of choices for quantities to be calculated from that radius:                         A         Area of a Circle                         C         Circumference of a Circle                         S          Surface Area of a Sphere                         V         Volume of a Sphere Prompt the user to enter the character corresponding to the quantity to be calculated. Use a switch statement to handle the calculations. Use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT