Question

Python please! Exercise #3: Design and implement a program (name it ArrayMethods), that defines 4 methods...

Python please!
Exercise #3: Design and implement a program (name it ArrayMethods), that defines 4 methods as follows:
int arrayMax(int[] arr) returns the maximum value in the an array
int arrayMin(int[] arr) returns the minimum value in an array
void arraySquared(int[] arr) changes every value in the array to its square (value²)
void arrayReverse(int[] arr) reverses the array (for example: array storing 7 8 9 becomes 9 8 7 )
The program main method creates a single-dimensional array of length 5 elements and initialize it with random integers between 1 and 100. The program displays the original array, then calls each of the above methods and displays their results as shown below. Document your code and organized your output following these sample runs.
1 0
Add a comment Improve this question Transcribed image text
Answer #1

Thats it !!! here is the code

---------------------------------------------------------------------------------------------------------------------------------

import random
#int arrayMax(int[] arr) returns the maximum value in the an array
def arrayMax(arr):
    highest_num=0
    for num in arr:
        if highest_num<num:
            highest_num=num
    return highest_num

# int arrayMin(int[] arr) returns the minimum value in an array
def arrayMin(arr):
    smallest_num=100
    for num in arr:
        if smallest_num>num:
            smallest_num=num
    return smallest_num

#void arraySquared(int[] arr) changes every value in the array to its square (value²)
def arraySquared(arr):
    return [x*x for x in arr]

#void arrayReverse(int[] arr) reverses the array (for example: array storing 7 8 9 becomes 9 8 7 )
def arrayReverse(arr):
    reverse_array=[]
    for i in range(len(arr)-1,-1,-1):
        reverse_array.append(arr[i])

    return reverse_array


def main():
    # create a list of 5 numbers in the range of 1 to 100
    random_array=[random.randint(1,100),random.randint(1,100),random.randint(1,100),\
                  random.randint(1,100),random.randint(1,100)]

    print("Original Array:",random_array)
    print("Max Number:",arrayMax(random_array))
    print("Min Number:",arrayMin(random_array))
    print("Squared Array:",arraySquared(random_array))
    print("Reversed Array:",arrayReverse(random_array))

if __name__ == '__main__':
    main()



------------------------------------------------------------------------------

Image screenshot

thank You !!!

plz a thumbs up : )

Add a comment
Answer #2
def arrayMax(arr):
    largest = arr[0]
    for num in arr:
        if num > largest:
            largest = num
    return largest


def arrayMin(arr):
    smallest = arr[0]
    for num in arr:
        if num < smallest:
            smallest = num
    return smallest


def arraySquared(arr):
    for i in range(len(arr)):
        arr[i] *= arr[i]


def arrayReverse(arr):
    for i in range(len(arr)//2):
        arr[i], arr[len(arr)-i-1] = arr[len(arr)-i-1], arr[i]


array = eval(input("Enter an array in list format: "))
print("Original array: " + str(array))
print("Max value: " + str(arrayMax(array)))
print("Min value: " + str(arrayMin(array)))
arraySquared(array)
print("Squared array: " + str(array))
arrayReverse(array)
print("Reversed array: " + str(array))

media%2F6f5%2F6f5c8015-a6e7-4e67-8c97-a6

Add a comment
Know the answer?
Add Answer to:
Python please! Exercise #3: Design and implement a program (name it ArrayMethods), that defines 4 methods...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design and implement a Java program (name it ArrayMethods ), that defines 4 methods as follows:...

    Design and implement a Java program (name it ArrayMethods ), that defines 4 methods as follows: int arrayMax (int [ ] arr) determines and returns the ma ximum value within an array int arrayMin (int [ ] arr) determines and returns the minimum value within an array void arraySquared (int [ ] arr) changes every value within the array to value

  • Design and implement a Java program (name it ArrayMethods), that defines 4 methods as follows: int...

    Design and implement a Java program (name it ArrayMethods), that defines 4 methods as follows: int arrayMax (int [ ] arr) determines and returns the maximum value within an array int arrayMin (int [ ] arr) determines and returns the minimum value within an array void arraySquared (int [] arr) changes every value within the array to value2 void arrayReverse (int [ ] arr) reverses the array (for example: 7 8 12 becomes 2 18 7) Test your methods by...

  • Exercise 5: Design and implement a Java program (name it ArrayMethods), that defines 4 methods as...

    Exercise 5: Design and implement a Java program (name it ArrayMethods), that defines 4 methods as follows: int arrayMax(int[] arr) determines and returns the largest value within an array int arrayMin(int[] arr) determines and returns the smallest value within an array void arrayReverse(int[] arr) reverses the array (for example: 7 8 1 2 becomes 2 1 8 7) void arraySquared(int[] arr) changes every value within the array to value² Test your methods by creating an array of length 5 within...

  • C++ ArrayMethods Program

    Exercise #3: Design and implement a program (name it ArrayMethods), that defines 4 methods as follows: int arrayMax(int[] arr) returns the maximum value in the an arrayint arrayMin(int[] arr) returns the minimum value in an arrayvoid arraySquared(int[] arr) changes every value in the array to its square (value²)void arrayReverse(int[] arr) reverses the array (for example: array storing 7   8   9  becomes 9   8   7 ) The program main method creates a single-dimensional array of length 5 elements and initialize it with random...

  • Please do in Java as simply as possible :) Exercise #3: Design and implement a program...

    Please do in Java as simply as possible :) Exercise #3: Design and implement a program (name it ArrayMethods), that defines 4 methods as follows: int arrayMax(int[] arr) returns the maximum value in the an array int arrayMin(int[] arr) returns the minimum value in an array void arraySquared(int[] arr) changes every value in the array to its square (value²) void arrayReverse(int[] arr) reverses the array (for example: array storing 7   8   9 becomes 9   8   7 ) The program main...

  • C++ Arrays & Methods

     #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns true (Boolean type) if the arrays store same values in the same order. Otherwise, it...

  • C++ Single Dimensional Arrays

    Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array.  The program...

  • SOLVE IN PYTHON: Exercise #2: Design and implement a program (name it CompareArrays) that compares the...

    SOLVE IN PYTHON: Exercise #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns true (Boolean type) if the arrays store same values in the...

  • IN PYTHON WITHOUT USING: .APPEND/ .SORT/ INSERT / .SPLIT Program 1: Design (pseudocode) and implement (source...

    IN PYTHON WITHOUT USING: .APPEND/ .SORT/ INSERT / .SPLIT Program 1: Design (pseudocode) and implement (source code) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional...

  • I need this in JAVA please: Design and implement a program (name it MinMaxAvg) that defines...

    I need this in JAVA please: Design and implement a program (name it MinMaxAvg) that defines three methods as follows: Method max (int x, int y, int z) returns the maximum value of three integer values. Method min (int X, int y, int z) returns the minimum value of three integer values. Method average (int x, int y, int z) returns the average of three integer values. In the main method, test all three methods with different input value read...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT