How to ask user for new item and add this to list (Python)How to read keyboard-input?How do I check if a list is empty?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow to print without newline or space?How do I sort a dictionary by value?How to make a flat list out of list of lists?Add new keys to a dictionary?How do I get the number of elements in a list in Python?How do I concatenate two lists in Python?How do I list all files of a directory?

Why would a new[] expression ever invoke a destructor?

How do you make your own symbol when Detexify fails?

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?

How do apertures which seem too large to physically fit work?

Pre-mixing cryogenic fuels and using only one fuel tank

Picking the different solutions to the time independent Schrodinger eqaution

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

How does a computer interpret real numbers?

Temporarily disable WLAN internet access for children, but allow it for adults

Store Credit Card Information in Password Manager?

Extract more than nine arguments that occur periodically in a sentence to use in macros in order to typset

Recommended PCB layout understanding - ADM2572 datasheet

What is the evidence for the "tyranny of the majority problem" in a direct democracy context?

Mixing PEX brands

Does Doodling or Improvising on the Piano Have Any Benefits?

Keeping a ball lost forever

Why is this estimator biased?

How should I respond when I lied about my education and the company finds out through background check?

Invalid date error by date command

What if a revenant (monster) gains fire resistance?

Unexpected behavior of the procedure `Area` on the object 'Polygon'

Can I say "fingers" when referring to toes?

How much character growth crosses the line into breaking the character

How can "mimic phobia" be cured or prevented?



How to ask user for new item and add this to list (Python)


How to read keyboard-input?How do I check if a list is empty?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow to print without newline or space?How do I sort a dictionary by value?How to make a flat list out of list of lists?Add new keys to a dictionary?How do I get the number of elements in a list in Python?How do I concatenate two lists in Python?How do I list all files of a directory?













0















I am learning python and already know how to add new items to a list by myself with append. I don't know the code to ask the user for a number and add this to the list.



Thanks in advance.



Marloes










share|improve this question



















  • 3





    What is it that you have tried so far?

    – DirtyBit
    Mar 7 at 6:31






  • 1





    Possible duplicate of How to read keyboard-input?

    – suicidalteddy
    Mar 7 at 6:34















0















I am learning python and already know how to add new items to a list by myself with append. I don't know the code to ask the user for a number and add this to the list.



Thanks in advance.



Marloes










share|improve this question



















  • 3





    What is it that you have tried so far?

    – DirtyBit
    Mar 7 at 6:31






  • 1





    Possible duplicate of How to read keyboard-input?

    – suicidalteddy
    Mar 7 at 6:34













0












0








0








I am learning python and already know how to add new items to a list by myself with append. I don't know the code to ask the user for a number and add this to the list.



Thanks in advance.



Marloes










share|improve this question
















I am learning python and already know how to add new items to a list by myself with append. I don't know the code to ask the user for a number and add this to the list.



Thanks in advance.



Marloes







python arrays list






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 7:22









Egon Allison

7161419




7161419










asked Mar 7 at 6:31









Marloes DelgijerMarloes Delgijer

12




12







  • 3





    What is it that you have tried so far?

    – DirtyBit
    Mar 7 at 6:31






  • 1





    Possible duplicate of How to read keyboard-input?

    – suicidalteddy
    Mar 7 at 6:34












  • 3





    What is it that you have tried so far?

    – DirtyBit
    Mar 7 at 6:31






  • 1





    Possible duplicate of How to read keyboard-input?

    – suicidalteddy
    Mar 7 at 6:34







3




3





What is it that you have tried so far?

– DirtyBit
Mar 7 at 6:31





What is it that you have tried so far?

– DirtyBit
Mar 7 at 6:31




1




1





Possible duplicate of How to read keyboard-input?

– suicidalteddy
Mar 7 at 6:34





Possible duplicate of How to read keyboard-input?

– suicidalteddy
Mar 7 at 6:34












5 Answers
5






active

oldest

votes


















0














Try the below code:



x = list() # Your list
x.append(1) # Appended by you
user = int(input("Enter Number")) #User Input
x.append(user) # Appended user input
print(x)





share|improve this answer























  • Accept the answer if u found it useful @Marloes Delgijer so that others could benefit. Thanks!

    – skaul05
    Mar 7 at 17:57


















0














some_List = [] # an empty list

for i in range(3): # a for-loop with 3 iteration
userInp = input("Enter a str to add to the list: ") # take the inp from user
some_List.append(userInp) # append that input to the list

print(some_List) # print the list


OUTPUT:



Enter a str to add to the list: 1
Enter a str to add to the list: a
Enter a str to add to the list: 2
['1', 'a', '2']





share|improve this answer






























    0














    Try this one in Python3



    listname = []
    inputdata = input("enter anything : ")
    listname.append(inputdata)
    print(inputdata)





    share|improve this answer























    • Thanks, this worked well.

      – Marloes Delgijer
      Mar 7 at 12:39


















    0














    You can use the inbuilt method 'input' to ask for input from the user.



    But remember one important thing, that whatever you will receive from that will be of the type str so make sure that you convert it according to your use case.



    number_list = list()

    number = input("Enter Number: ")

    # now for your use case since you are dealing with numbers, convert the input into int
    number = int(number)

    number_list.append(number)





    share|improve this answer






























      0














      This should work:



      your_list.append(int(input("Enter Number:")))


      The append() adds to the end of your_list.
      The input() requests a number from the user. It will be converted to an integer.




      Note: the code does not checks the user gave you an actual number.







      share|improve this answer
























        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037417%2fhow-to-ask-user-for-new-item-and-add-this-to-list-python%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        Try the below code:



        x = list() # Your list
        x.append(1) # Appended by you
        user = int(input("Enter Number")) #User Input
        x.append(user) # Appended user input
        print(x)





        share|improve this answer























        • Accept the answer if u found it useful @Marloes Delgijer so that others could benefit. Thanks!

          – skaul05
          Mar 7 at 17:57















        0














        Try the below code:



        x = list() # Your list
        x.append(1) # Appended by you
        user = int(input("Enter Number")) #User Input
        x.append(user) # Appended user input
        print(x)





        share|improve this answer























        • Accept the answer if u found it useful @Marloes Delgijer so that others could benefit. Thanks!

          – skaul05
          Mar 7 at 17:57













        0












        0








        0







        Try the below code:



        x = list() # Your list
        x.append(1) # Appended by you
        user = int(input("Enter Number")) #User Input
        x.append(user) # Appended user input
        print(x)





        share|improve this answer













        Try the below code:



        x = list() # Your list
        x.append(1) # Appended by you
        user = int(input("Enter Number")) #User Input
        x.append(user) # Appended user input
        print(x)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 6:33









        skaul05skaul05

        1,0891616




        1,0891616












        • Accept the answer if u found it useful @Marloes Delgijer so that others could benefit. Thanks!

          – skaul05
          Mar 7 at 17:57

















        • Accept the answer if u found it useful @Marloes Delgijer so that others could benefit. Thanks!

          – skaul05
          Mar 7 at 17:57
















        Accept the answer if u found it useful @Marloes Delgijer so that others could benefit. Thanks!

        – skaul05
        Mar 7 at 17:57





        Accept the answer if u found it useful @Marloes Delgijer so that others could benefit. Thanks!

        – skaul05
        Mar 7 at 17:57













        0














        some_List = [] # an empty list

        for i in range(3): # a for-loop with 3 iteration
        userInp = input("Enter a str to add to the list: ") # take the inp from user
        some_List.append(userInp) # append that input to the list

        print(some_List) # print the list


        OUTPUT:



        Enter a str to add to the list: 1
        Enter a str to add to the list: a
        Enter a str to add to the list: 2
        ['1', 'a', '2']





        share|improve this answer



























          0














          some_List = [] # an empty list

          for i in range(3): # a for-loop with 3 iteration
          userInp = input("Enter a str to add to the list: ") # take the inp from user
          some_List.append(userInp) # append that input to the list

          print(some_List) # print the list


          OUTPUT:



          Enter a str to add to the list: 1
          Enter a str to add to the list: a
          Enter a str to add to the list: 2
          ['1', 'a', '2']





          share|improve this answer

























            0












            0








            0







            some_List = [] # an empty list

            for i in range(3): # a for-loop with 3 iteration
            userInp = input("Enter a str to add to the list: ") # take the inp from user
            some_List.append(userInp) # append that input to the list

            print(some_List) # print the list


            OUTPUT:



            Enter a str to add to the list: 1
            Enter a str to add to the list: a
            Enter a str to add to the list: 2
            ['1', 'a', '2']





            share|improve this answer













            some_List = [] # an empty list

            for i in range(3): # a for-loop with 3 iteration
            userInp = input("Enter a str to add to the list: ") # take the inp from user
            some_List.append(userInp) # append that input to the list

            print(some_List) # print the list


            OUTPUT:



            Enter a str to add to the list: 1
            Enter a str to add to the list: a
            Enter a str to add to the list: 2
            ['1', 'a', '2']






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 7 at 6:33









            DirtyBitDirtyBit

            10.1k21540




            10.1k21540





















                0














                Try this one in Python3



                listname = []
                inputdata = input("enter anything : ")
                listname.append(inputdata)
                print(inputdata)





                share|improve this answer























                • Thanks, this worked well.

                  – Marloes Delgijer
                  Mar 7 at 12:39















                0














                Try this one in Python3



                listname = []
                inputdata = input("enter anything : ")
                listname.append(inputdata)
                print(inputdata)





                share|improve this answer























                • Thanks, this worked well.

                  – Marloes Delgijer
                  Mar 7 at 12:39













                0












                0








                0







                Try this one in Python3



                listname = []
                inputdata = input("enter anything : ")
                listname.append(inputdata)
                print(inputdata)





                share|improve this answer













                Try this one in Python3



                listname = []
                inputdata = input("enter anything : ")
                listname.append(inputdata)
                print(inputdata)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 7 at 6:36









                priyank modipriyank modi

                262




                262












                • Thanks, this worked well.

                  – Marloes Delgijer
                  Mar 7 at 12:39

















                • Thanks, this worked well.

                  – Marloes Delgijer
                  Mar 7 at 12:39
















                Thanks, this worked well.

                – Marloes Delgijer
                Mar 7 at 12:39





                Thanks, this worked well.

                – Marloes Delgijer
                Mar 7 at 12:39











                0














                You can use the inbuilt method 'input' to ask for input from the user.



                But remember one important thing, that whatever you will receive from that will be of the type str so make sure that you convert it according to your use case.



                number_list = list()

                number = input("Enter Number: ")

                # now for your use case since you are dealing with numbers, convert the input into int
                number = int(number)

                number_list.append(number)





                share|improve this answer



























                  0














                  You can use the inbuilt method 'input' to ask for input from the user.



                  But remember one important thing, that whatever you will receive from that will be of the type str so make sure that you convert it according to your use case.



                  number_list = list()

                  number = input("Enter Number: ")

                  # now for your use case since you are dealing with numbers, convert the input into int
                  number = int(number)

                  number_list.append(number)





                  share|improve this answer

























                    0












                    0








                    0







                    You can use the inbuilt method 'input' to ask for input from the user.



                    But remember one important thing, that whatever you will receive from that will be of the type str so make sure that you convert it according to your use case.



                    number_list = list()

                    number = input("Enter Number: ")

                    # now for your use case since you are dealing with numbers, convert the input into int
                    number = int(number)

                    number_list.append(number)





                    share|improve this answer













                    You can use the inbuilt method 'input' to ask for input from the user.



                    But remember one important thing, that whatever you will receive from that will be of the type str so make sure that you convert it according to your use case.



                    number_list = list()

                    number = input("Enter Number: ")

                    # now for your use case since you are dealing with numbers, convert the input into int
                    number = int(number)

                    number_list.append(number)






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 7 at 6:42









                    Abhinav AnandAbhinav Anand

                    996




                    996





















                        0














                        This should work:



                        your_list.append(int(input("Enter Number:")))


                        The append() adds to the end of your_list.
                        The input() requests a number from the user. It will be converted to an integer.




                        Note: the code does not checks the user gave you an actual number.







                        share|improve this answer





























                          0














                          This should work:



                          your_list.append(int(input("Enter Number:")))


                          The append() adds to the end of your_list.
                          The input() requests a number from the user. It will be converted to an integer.




                          Note: the code does not checks the user gave you an actual number.







                          share|improve this answer



























                            0












                            0








                            0







                            This should work:



                            your_list.append(int(input("Enter Number:")))


                            The append() adds to the end of your_list.
                            The input() requests a number from the user. It will be converted to an integer.




                            Note: the code does not checks the user gave you an actual number.







                            share|improve this answer















                            This should work:



                            your_list.append(int(input("Enter Number:")))


                            The append() adds to the end of your_list.
                            The input() requests a number from the user. It will be converted to an integer.




                            Note: the code does not checks the user gave you an actual number.








                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Mar 7 at 9:38









                            DirtyBit

                            10.1k21540




                            10.1k21540










                            answered Mar 7 at 8:33









                            user3559221user3559221

                            42




                            42



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037417%2fhow-to-ask-user-for-new-item-and-add-this-to-list-python%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                                Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                                Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved