Question

Create a Python program that populates an array variable whose values(at least 5) are input by...

Create a Python program that populates an array variable whose values(at least 5) are input by the user. It should then perform some modification to each element of array using a loop and then display the modified array in a second loop. Include Header comments in your program that describe what the program does.

Homework Answers

Answer #1

1. Example with numbers:

Python Code for modifying the number to square of that number and displaying using loop is given below:

# define a empty list which is similar to an array
array = []

# Size of array is asked from user 
# As input function returns string value so int() function is used for type conversion 
array_size = int(input("Enter the size of array: "))

# User is pompt to enter the values 
for i in range(array_size):
    user_input = int(input ("Enter the number {} : ".format(i+1) ))
    array.append(user_input)

# Modification part here provided numbers are squared and stored in same array list    
print("\n***processing modification***")
for index, value in enumerate(array):
    array[index] = value ** 2

# Print the squared values of the numbers
print("\nThe square of provided numbers :")
for index, value in enumerate(array):
    print("Square of number" + str(index+1) + " : " + str(array[index]))

Output:

2. Example with strings:

Python Code for modifying the names to reverse of the name and displaying using loop is given below:

# define a empty list which is similar to an array
array = []

# Size of array is asked from user 
# As input function returns string value so int() function is used for type conversion 
array_size = int(input("Enter the size of array: "))

# User is pompt to enter the names 
for i in range(array_size):
    user_input = input ("Enter the Name {} : ".format(i+1) )
    array.append(user_input)

# Modification part here provided names ae reversed and stored in same array list    
print("\n***processing modification***")
for index, value in enumerate(array):
    # array[index][start:end:step] -->  element at each index are reversed using step -1 
    array[index] = array[index][::-1]  

# Print the reversed names from input
print("\nThe reverse of provided names :")
for index, value in enumerate(array):
    print("Reverse of the name " + str(index+1) + " : " + array[index])

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Post a Python program with a scenario that accepts at least three values as input, performs...
Post a Python program with a scenario that accepts at least three values as input, performs some computation and displays at least two values as the result. The program must include an if statement that performs different computations based on the value of one of the inputs. Include comments in your program that describe what the program does. Also post a screen shot of executing your program on at least two test cases.
In this lab, you complete a partially prewritten C++ program that uses an array. The program...
In this lab, you complete a partially prewritten C++ program that uses an array. The program prompts the user to interactively enter eight batting averages, which the program stores in an array. The program should then find the minimum and maximum batting average stored in the array as well as the average of the eight batting averages. The data file provided for this lab includes the input statement and some variable declarations. Comments are included in the file to help...
Develop a C++ program that determines the largest and second largest positive values in a collection...
Develop a C++ program that determines the largest and second largest positive values in a collection of data Prompt the user to enter integer values until they enter any negative value to quit You may presume the user will input at least two valid integer values Create a loop structure of some sort to execute this input cycle Maintain the largest and second largest integer as the user inputs data This logic should be placed inside your loop structure Arrays...
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
Programing lanugaue is C++ Plan and code a menu-driven modular program utilizing an array An input...
Programing lanugaue is C++ Plan and code a menu-driven modular program utilizing an array An input file has an unknown number of numeric values(could be empty too).Read the numbers from the input fileand store even numbers in one arrayand odd numbers in another array.Create menu options to Display count of even numbers, count of odd numbersand the sum values in each array Determine the average of each array Determine the median of each array Sort each array in ascending order(use...
Question 5: Recommend / Explain a C++ program which uses an array of 20 integers whose...
Question 5: Recommend / Explain a C++ program which uses an array of 20 integers whose input is taken by user, the array is passed to a functions named i.e. smallest(int A[20) and largest(int B[20]) to determine minimum and maximum values respectively. Also create a function named modify(int *p) which modifies the value at the index given by user.
Write a Java program to randomly create an array of 50 double values. Prompt the user...
Write a Java program to randomly create an array of 50 double values. Prompt the user to enter an index and prints the corresponding array value. Include exception handling that prevents the program from terminating if an out of range index is entered by the user. (HINT: The exception thrown will be ArrayIndexOutOfBounds)
Write a java program that creates an integer array with 50 random values, prompts the user...
Write a java program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. “Out of Bounds”) and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle invalid inputs,...
Create a program that allows the user to input a list of first names into one...
Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. The output should be a list of emial addresses where the address is of the following form: [email protected] Declare FirstName[100] as String Declare LastName[100] as String Declare email as String Declare K as Integer Declare index as Integer Write "Enter first and last name." Write...
Python code only! (Do not include breaks or continue functions) Write a program that asks the...
Python code only! (Do not include breaks or continue functions) Write a program that asks the user to enter the amount that they budgeted for the month. A loop should then prompt the user to enter their expenses, one at a time and to enter 0 to quit. When the loop finishes, the program should display the the amount of budget left. (a negative number indicates the user is over budget and a positive number indicates the user is under...