This content originally appeared on DEV Community and was authored by rrtutors
Create two arrays one contains three numbers that the user enters and other containing a set of five random numbers. Join these two arrays and display this array
from array import *
import random
num1 = array('i', [])
num2 = array('i', [])
for i in range(0, 3):
num = int(raw_input("Enter a number: "))
num1.append(num)
print("Second Random Array")
for i in range(0, 5):
num = random.randint(1, 100)
num2.append(num)
print("Join two Arrays")
num1.extend(num2)
for i in num1:
print(i)
print("Sort Joined Array")
num1 = sorted(num1)
for i in num1:
print(i)
In the above example we create
Output
Enter a number: 12
Enter a number: 23
Enter a number: 45
Second Random Array
Join two Arrays
12
23
45
85
77
86
71
22
Sort Joined Array
12
22
23
45
71
77
85
86
Python Array Examples
This content originally appeared on DEV Community and was authored by rrtutors
rrtutors | Sciencx (2021-11-18T18:12:32+00:00) Python array Example – Create two different arrays and join them. Retrieved from https://www.scien.cx/2021/11/18/python-array-example-create-two-different-arrays-and-join-them/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.