Skip to main content

CS / IP - LIST OPERATIONS - PROJECT - 16TH AUG 24

 

LIST OPERATIONS- PROJECT FOR BEGINNERS

# -*- coding: utf-8 -*-

"""

Created on Fri Aug 16 10:18:23 2024

@author: Kirti Hora

"""


myList = [] #myList having 5 elements

choice = 0

print("\nL I S T O P E R A T I O N S")

ans='y'

while ans=='y':

    print(" 1. Append an element")

    print(" 2. Insert an element at the desired position")

    print(" 3. Append a list to the given list")

    print(" 4. Modify an existing element")

    print(" 5. Delete an existing element by its position")

    print(" 6. Delete an existing element by its value")       

    print(" 7. Sort the list in ascending order")

    print(" 8. Sort the list in descending order")

    print(" 9. Display the list")

    choice = int(input("ENTER YOUR CHOICE (1-9): "))

    #append element

    if choice == 1:

        #WAP to append an element in a list

        n =int (input("Enter no of elements"))

        i=0

        while i < n:

            num= int(input("Enter element " + str(i) + ": "))

            myList+=[num]  

            i+=1

        print("The elements have been appended\n")

    #insert an element at desired position

    elif choice == 2:

        #WAP to insert element at a particular position

        element = eval(input("Enter the element to be inserted: "))

        pos = int(input("Enter the position:"))

        myList.insert(pos,element)

        print("The element has been inserted\n")

    elif choice == 3:

       # WAP to enter list in the existing list

        newList = eval(input("Enter the list to be appended: "))

        myList.extend(newList)

        print("The list has been appended\n")

    #modify an existing element

    elif choice == 4:

        #WAP to to modify the element in the list

        i = int(input("Enter the position of the element to be modified: "))

        if i < len(myList):

            newElement = eval(input("Enter the new element: "))

            oldElement = myList[i]

            myList[i] = newElement

            print("The element",oldElement,"has been modified\n")

        else:

            print("Position of the element is more then the length of list")

    #delete an existing element by position

    elif choice == 5:

        #WAP to select the element on particular position

        i = int(input("Enter the position of the element to be deleted: "))

        if i < len(myList):

            element = myList.pop(i)

            print("The element",element,"has been deleted\n")

        else:

            print("\nPosition of the element is more then the length of list")

    #delete an existing element by value

    elif choice == 6:

       # WAP to remove particular element from  the list

        element = int(input("\nEnter the element to be deleted: "))

        if element in myList:

            myList.remove(element)

            print("\nThe element",element,"has been deleted\n")

        else:

            print("\nElement",element,"is not present in the list")

    #list in sorted order

    elif choice == 7:

       # WAP to sort the given list

        myList.sort()

        print("\nThe list has been sorted")

    #list in reverse sorted order

    elif choice == 8:

       # WAP a to print list in reverse order

        myList.sort(reverse = True)

        print("\nThe list has been sorted in reverse order")

    #display the list

    elif choice == 9:

        print("\nThe list is:", myList)

    else:

        print("Choice is not valid")

        ans=input("Do you want to continue..")

else:

    print("Terminating")

Comments

Popular posts from this blog

GRADE XII - Python Connectivity with MySQL

  Python Connectivity with MySQL In real-life applications, the data inputted by the user and processed by the application needs to be saved permanently, so that it can be used for future manipulation. Usually, input and output data is displayed during execution but not stored, as it resides in main memory , which is temporary — i.e., it gets erased once the application is closed. This limitation can be overcome by sending the data to be stored in a database , which is made accessible to the user through a Front-End interface . Key Concepts Database A database is an organized collection of data that is stored and accessed electronically from a computer system. DBMS (Database Management System) A DBMS is software that interacts with end-users, applications, and the database to capture and analyze data. Front-End The Front-End is the user interface of the application, responsible for input/output interaction with the user. Back-End The Back-End refe...

GRADE XI | DESIGN THINKING & INNOVATION (848) | INTRO | CH-1

  DESIGN THINKING &  INNOVATION (848)  INTRODUCTION LINK : INTRODUCTION PPT PPT LINK Notes: Design Thinking and Innovation Grade XI Introduction Section   I. What is Design? (0.1.1) Definitions from Experts: John Maeda: "Design is solution to a problem". Saul Bass: "Design is thinking made visual". Charles Eames:   “Design is a plan for arranging elements in such a way as best to accomplish a particular purpose.” Steve Jobs:  "Design is not just what it looks like and feels like. Design is how it works". Prof. Sudhakar Nadkarni:  "Essentials of design are— purity, precision, details". Design is a way of understanding needs, identifying problems, and creating appropriate and innovative solutions. It is not only about appearance, but also about usefulness and sustainability. Design is explained as something that helps solve problems and make a positive difference. Key ...