-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiple_input_program.py
More file actions
74 lines (61 loc) · 2.14 KB
/
multiple_input_program.py
File metadata and controls
74 lines (61 loc) · 2.14 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# This file is part of the Python Projects repository, which is licensed under the
# Apache License, Version 2.0. You may obtain a copy of the license at
#
# http://www.apache.org/licenses/LICENSE-2.0
"""
Multiple Input from User Program.
Input:
- 'stop' to end the program.
- 'display' to show the entered inputs.
- 'clear' to reset and clear the entered inputs.
- Any other input is considered as regular text input.
Output:
- Displays each regular text input.
- Shows the count of inputs entered.
Features:
- Continuously receives inputs from the user until the input is 'stop'.
- Tracks the count of inputs entered.
- Allows the user to display the entered inputs.
- Provides an option to clear the entered inputs.
- Handles invalid input and exceptions gracefully.
- Provides a simple and intuitive command-line interface for users to interact with the program.
"""
def display_user_inputs(inputs: list):
"""
Display the entered inputs from the user.
Args:
- inputs (list): List of user inputs to display.
"""
if inputs:
print("\n\tEntered Inputs:")
for i, user_input in enumerate(inputs, 1):
print(f"\t{i}. {user_input}")
else:
print("\tNo inputs entered yet.")
if __name__ == '__main__':
user_inputs = []
while True:
# Receive input from the user.
reply = input(
"\n\tMenu-\n\
'Stop' - end\n\
'Display' - Display text\n\
'Clear' - Reset\t\t\
\n\n\tEnter text: "
)
# Check if the user wants to stop the program.
if reply.lower() == 'stop':
display_user_inputs(user_inputs)
break
# Check if the user wants to display the entered inputs.
elif reply.lower() == 'display':
display_user_inputs(user_inputs)
# Check if the user wants to clear the entered inputs.
elif reply.lower() == 'clear':
user_inputs = []
print("\t\tEntered inputs cleared.")
# Regular text input.
else:
user_inputs.append(reply)
print(f"\tInput '{reply}' recorded.")
print("\nProgram ended.")