Question

USING C++ and PYTHON Please Help me: 1. Write a function that takes in an array...

USING C++ and PYTHON Please Help me:

1. Write a function that takes in an array of integers (and the size of the array in the C/C++ version). The function will reverse the array of integers and return the reversed array. Print the array that is returned from the function. How you "return" the array is up to you, but do not overwrite the original array. Note: in Python, the term list is more appropriate, see https://docs.python.org/3.5/tutorial/datastructures.html
a) Example input: {2, 4, 3, 7, 1}
Example return: {1, 7, 3, 4, 2}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def reverseNums(nums):
        reversArr = []
        # write a reverse loop, that runs from right to left
        for i in range(len(nums) - 1, -1, -1):
                reversArr.append(nums[i])
        return reversArr

original = [2, 4, 3, 7, 1]
print(reverseNums(original))

Please upvote. Thanks!

Add a comment
Know the answer?
Add Answer to:
USING C++ and PYTHON Please Help me: 1. Write a function that takes in an array...
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
  • Python: P2 Write a function that reverses a python list using recursion (Chapter 6-3 in our...

    Python: P2 Write a function that reverses a python list using recursion (Chapter 6-3 in our textbook) E.g.: Input: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Constraints: - List elements are integers - The function should return a reversed array, not print its elements You may use the following code as template: def reverse(my_list, index = None): # your code here

  • Write a method that takes two arrays of integers and return and array that is the...

    Write a method that takes two arrays of integers and return and array that is the union of both arrays. For instance, the first array contains (1,2,3), the second array(4,5,6), the returned array should contain (1,2,3,4,5,6) (3.5 points) Write a method that takes and an array and return the reverse of that array. For instance, if the array is (1,2,3), the returned array should be (3,2,1) (3.5 points)

  • Code in C++ please! Write a function that takes an array of integers as an input...

    Code in C++ please! Write a function that takes an array of integers as an input parameter (the address of the first value of the array). It returns nothing. It prints out the array as a single line, with commas between each number, and when the array is finished being printed, it prints an endl; so that we flush the buffer and move to a new line. (I’m having you write this function because you’ll be wanting to print out...

  • 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N  (that is not more than 50) from standard input and then reads N  integers from a file named...

  • Write a C++ console application that reverses an array of characters, and counts the number of:...

    Write a C++ console application that reverses an array of characters, and counts the number of:           Lower case characters (islower)           Upper case characters (isupper)           Digits (isdigit)           Other (not one of previous) Create four global variables to hold these counts. Create function void count(char input[], char reverse[]) that takes as input two arrays: one that contains characters and another that will contain the reverse of that array. The function will reverse the input array and do the...

  • Python Question? Write a function called reverse(user_list, num = -1) that takes a list and a...

    Python Question? Write a function called reverse(user_list, num = -1) that takes a list and a number as parameters. The function returns a copy of the list with the first number of items reversed. Conditions: The number parameter must be a default argument. -      If the default argument for number is given in the function call, only the first number of items are reversed. -      If the default argument for number is not provided in the function call, then the...

  • C++ Write a function that takes as an input parameter a matrix of integers, and 2...

    C++ Write a function that takes as an input parameter a matrix of integers, and 2 integers representing the matrix’s dimensions. Print out the transposed version of the matrix. Input: [[1 2 3] 3,3 ->1 4 7 [4 5 6] 2 5 8 [7 8 9]] 3 6 9

  • Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...

    Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. To test your function, write a main that prompts a user for a list of 15 integers and outputs the index and value of the first occurrence of the smallest value. The program should print out Enter 15 integers: The position of the first occurrence of the smallest element in...

  • Using C, Write a function reverse which takes a string as an argument, reverses the string...

    Using C, Write a function reverse which takes a string as an argument, reverses the string and returns the reversed string. Note; you should not return a string that you created inside the reverse function! For example: Test char str[]-"hello" printf("%s", reverse (str)); Result olleh

  • Done in C++ using visual studio 1. Write a program with one additional function called int[]...

    Done in C++ using visual studio 1. Write a program with one additional function called int[] reverseArray(int array). This function will receive an array from main and then reverse and should return the reversed array to the main to print out. Use a single array and a single loop, you’re are neither allowed to print out just in reverse order nor allowed to use another array variable to store the original array in reverse order. 2. Write a program which...

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