Python Programs Written and Practiced by : Jiya Kiyam

File Name : menu_given_program1.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
"""
Program Name: Perform common functions on menu
Description: append, insert, index, count, sort, min, max, pop, remove
"""

perform_on = input("Enter numbers giving space : ")
perform_on = perform_on.split()
x = []
i = 0
while i < len(perform_on) :
    x.append(int(perform_on[i]))
    i +=1
option = input("Option : \n1. append \n2. insert \n3. index \n4. count \n5. sort \n6. min \n7. max \n8. pop \n9. remove \nEnter your choice : ")
if option == "1" :
    n = input("Enter number to append : ")
    x.append(int(n))
    print(f"Updated list : {x}")
elif option == "2" :
    index = int(input("Enter index to insert :"))
    n = int(input("Enter number to insert : "))
    x.insert(index, n)
    print(f"Updated list : {x}")
elif option == "3" :
    n = int(input("Enter number to find index : "))
    if n in x :
        print(f"Index : {x.index(n)}")
    else :
        print("Index number not found.")
elif option == "4" :
    n = int(input("Enter the number to count in list  : "))
    print(f"Count : {x.count(n)}")
elif option == "5" :
    x.sort()
    print(f"Sorted list : {x}")
elif option == "6" :
    print(f"Minimum number : {min(x)}")
elif option == "7" :
    print(f"Maximum number : {max(x)}")
elif option == "8" :
    if len(x) > 0 :
        index = int(input("Enter index to pop : "))
        if index < len(x) :
             x.pop(index)
             print(f"Updated list : {x}")
        else : 
             print("Invalid Index")
    else :
        print("List is empty")
elif option == "9" :
    n = int(input("Enter number to remove :"))
    if n in x : 
        x.remove(n)
        print(f"Updated list : {x}")
    else :
        print(f"{n} is already not present in the list.")
else :
    print("Invalid option")

Run Back to programs