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.
Post a Python program that accepts at least two values as input, performs some computation and...
Post a Python program that accepts at least two values as input, performs some computation and displays at least one value as the result. The computation must involve calling one of the predefined functions in the math library. Include comments in your program that describe what the program does. Also post a screen shot of executing your program on at least one test case. Be sure to choose a program different from any of the programs already posted by your...
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.
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January - December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
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)
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT