FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CCDATRCL/ProblemSet/Week 2/Problem/Python/Stack.py at main · flexycode/CCDATRCL · GitHub
flexycode
/
CCDATRCL
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
9
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
CCDATRCL
/
ProblemSet
/
Week 2
/
Problem
/
Python
/
Stack.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
44 lines (35 loc) · 1.36 KB
Breadcrumbs
CCDATRCL
/
ProblemSet
/
Week 2
/
Problem
/
Python
/
Stack.py
Copy path
File metadata and controls
44 lines (35 loc) · 1.36 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
stack
=
[]
# Ask the user to enter the number of elements to push onto the stack
num_elements
=
int
(
input
(
"Enter the number of elements to push onto the stack: "
))
# Ask the user to enter the elements to push onto the stack
for
i
in
range
(
num_elements
):
element
=
int
(
input
(
f"Element
{
i
+
1
}
: "
))
stack
.
append
(
element
)
# Print the stack elements
print
(
"Stack elements:"
)
print
(
stack
)
# Ask the user if they want to pop an element from the stack
input_str
=
input
(
"Do you want to pop an element from the stack? (yes/no): "
)
if
input_str
.
lower
()
==
"yes"
:
# Pop an element from the stack
if
stack
:
popped_element
=
stack
.
pop
()
print
(
"Popped element: "
+
str
(
popped_element
))
else
:
print
(
"Stack is empty. Cannot pop an element."
)
# Print the updated stack elements
print
(
"Updated stack elements:"
)
print
(
stack
)
else
:
print
(
"No element popped from the stack."
)
# Ask the user if they want to push another element onto the stack
input_str
=
input
(
"Do you want to push another element onto the stack? (yes/no): "
)
if
input_str
.
lower
()
==
"yes"
:
# Ask the user to enter the new element
new_element
=
int
(
input
(
"Enter the new element: "
))
stack
.
append
(
new_element
)
# Print the updated stack elements
print
(
"Updated stack elements:"
)
print
(
stack
)
else
:
print
(
"No new element pushed onto the stack."
)
Back
|
FazBrowse Home
|
New Git URL