-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexercise_27.py
70 lines (61 loc) · 1.93 KB
/
exercise_27.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
print(
'-----------------------------------------\n'\
'Practical python education || Exercise-27:\n'\
'-----------------------------------------\n'
)
print(
'Task:\n'\
'-----------------------------------------\n'\
'Write a Python program to concatenate all elements in a list into a string and return it.\n'
)
print(
'Solution:\n'\
'-----------------------------------------'\
)
#Default function for handling execution loop:
def execution_loop():
data = input("Do you want to try again ? Enter [y] - for continue / [n] - for quit : ")
if data == "y":
return True
elif data == "n":
return False
else:
print("Error: your entered incorrect command. Please, try again...")
execution_loop()
#Function for concatenating all list elements and returns a string from them:
def concatenating_list_data(list):
result = ''
for element in list:
result += str(element)
print(result)
#Default parameter for handling execution loop:
again_exec = True
counter_exec = 0
#Default loop for handling execution:
while again_exec:
user_list_length = int(input("Please, enter length of your list = "))
if user_list_length < 0:
print("Error: Lenght of the list cannot be a negative number. Please, try again...")
continue
elif user_list_length == 0:
print("Error: The list must have at least one item. Please, try again...")
continue
else:
user_list = []
output = ''
for i in range(user_list_length):
print("%dth: " % i)
user_list.append(input())
print("Your entered list data: ", user_list)
concatenating_list_data(user_list)
again_exec = execution_loop()
counter_exec = counter_exec + 1
#The end of execution:
if again_exec == False:
print("Program was executed: ",counter_exec, ' times.')
break
print(
'\n-----------------------------------------\n'\
'Copyright 2019 Vladimir Pavlov. All Rights Reserved.\n'\
'-----------------------------------------'
)