-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.py
More file actions
48 lines (36 loc) · 1.2 KB
/
array.py
File metadata and controls
48 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def process_and_insert(array, target):
new_array = []
# Iterate through the range from 1 to range_end (inclusive)
for i in range(1, (len(array)+target) + 1):
# Add each number to the new_array
new_array += [i]
return new_array
def parse_input(input_number):
array = []
num_str = ''
for char in input_number:
if char == '[' or char == ']':
# Skip brackets
pass
elif char == ',':
# Convert num_str to integer if it's not empty
if num_str != '':
array += [int(num_str)]
num_str = '' # Reset num_str
else:
# Accumulate characters for num_str
num_str += char
# Convert the last number if num_str is not empty
if num_str != '':
array += [int(num_str)]
return array
# Get user input for the array
input_number = int(input("Enter the array elements as a number [1,3,5,7,9]: "))
# Parse the input string to get the array
array = parse_input(input_number)
# Set the target value (default is 2)
target = 2
# Generate the complete list
result = process_and_insert(array, target)
print("Resulting array:", result)
# type: ignore