Day 7: Arrays

  • Instructions:
    • Given an array of N integers, print the integers in reverse order on a single line with a space between each character
    • Constraints:
      • 1 <= N <= 1000
      • 1 <= A[i] <= 1000, where A[i] is the i'th integer of the array
    Excercise
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    if __name__ == '__main__':
        n = int(input().strip())
    
        arr = list(map(int, input().rstrip().split()))
    
    Solution
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    if __name__ == '__main__':
        n = int(input().strip())
    
        arr = list(map(int, input().rstrip().split()))
    
        x = len(arr)-1
        s = ""
    
        while x >= 0:
            s+= "{} ".format(arr[x])
            x-=1
    
        print(s)