Skip to content

Commit ee3f6d1

Browse files
authored
Add files via upload
1 parent 05fb1b4 commit ee3f6d1

1 file changed

Lines changed: 92 additions & 22 deletions

File tree

Python/program-32/program.py

Lines changed: 92 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,92 @@
1-
def make_readable(s):
2-
t = ['00','00','00']
3-
def c(a):
4-
if len(a) == 2 : return str(a)
5-
else: return '0'+str(a)
6-
7-
if s < 60:
8-
t[2] = c(str(s))
9-
10-
elif s >= 60 and s < 3600:
11-
t[1] = c(str(int(s/60)))
12-
t[2] = c(str(s%60))
13-
14-
else:
15-
t[0] = c(str(int(s/3600)))
16-
t[1] = c(str(int((s%3600)/60)))
17-
t[2] = c(str(((s%3600)%60)))
18-
19-
return f'{t[0]}:{t[1]}:{t[2]}'
20-
21-
# print(make_readable(359999)) output: 99:59:59
22-
# print(make_readable(9678)) output: 2:41:18
1+
# Made by Nitin Kumar
2+
# on 15th September 2020
3+
# using purely python language
4+
# and list 'data structure' type
5+
# comments are added for clear understanding of every code used
6+
# open source for learning
7+
8+
9+
# -----------------------------DATA STRUCTURE IN PYTHON USING LIST----------------------------------------
10+
11+
12+
# declaring & initializing list named 'tree'
13+
tree=[]
14+
15+
# option by default 'y'
16+
ans = 'Y'
17+
18+
# loop to constantly ask what to do
19+
while ans == 'Y' or ans == 'y':
20+
21+
# FUNCTION USED IN THIS DATA STRUCTURE
22+
23+
# function to insert multiple items in lists
24+
def insert_items():
25+
nol = int(input("Enter the number of items to fill in the tree:\t"))
26+
for i in range(0,nol):
27+
i = int(input("Enter the items:\t"))
28+
tree.append(i)
29+
30+
# function to display items in the list
31+
def display_items():
32+
if tree == []:
33+
print("You haven't added any item !!")
34+
else:
35+
print("The tree made is",tree)
36+
37+
# funtion to add one item to the list
38+
def add_item():
39+
index = int(input("Enter the index of element after which you want to add item:\t"))
40+
item = int(input("Enter the value:\t"))
41+
tree.insert(index,item)
42+
43+
# function to delete item in list
44+
45+
# function to delete item when value of item to be deleted is known
46+
def delete_item_value():
47+
value = int(input("Enter the value of element which you want to delete:\t"))
48+
tree.remove(value)
49+
50+
# function to delete item when index of item to be deleted is known
51+
def delete_item_index():
52+
index = int(input("Enter the index of element which you want to delete:\t"))
53+
tree.pop(index)
54+
55+
# MAIN THING TO BE DISPLAYED EVERYTIME YOU TYPE 'Y' OR 'y' TO DO TASKS INSIDE THE TREE
56+
57+
# 1. ADD MULTIPLE ITEMS IN TREE
58+
# 2. DISPLAY ITEMS
59+
# 3. ADD ONE ITEM ONLY
60+
# 4. DELETE ITEM IF
61+
# 41. VALUE OF ITEM TO BE DELETED IS KNOWN
62+
# 42. INDEX OF ITEM TO BE DELETED IS KNOWN
63+
# 5. EXIT
64+
65+
try:
66+
print("\n\n========================================")
67+
option = int(input("What do you want to do ? \n1. Add multiple items\n2. Display items\n3. Add one item\n4. Delete item when\n\t 41. You know the value of item\n\t 42. You know the index of item\n5. Exit\n\nYOUR ANSWER HERE\t"))
68+
print("========================================\n\n")
69+
70+
# CONDITIONS TO BE FOLLOWED FOR SUCCESSFUL EXECUTION
71+
72+
if option == 1:
73+
insert_items()
74+
elif option == 2:
75+
display_items()
76+
elif option == 3:
77+
add_item()
78+
elif option == 41:
79+
delete_item_value()
80+
elif option == 42:
81+
delete_item_index()
82+
elif option == 5:
83+
exit()
84+
else:
85+
print("Invalid option selected , Try again !!")
86+
87+
except:
88+
print("Please choose number from 1 to 5")
89+
90+
91+
#Question asked for next iteration
92+
ans = input("Do you want to continue ? ( type 'Y' or 'y' to continue )\t")

0 commit comments

Comments
 (0)