3 Replies - 185 Views - Last Post: 05 November 2019 - 02:45 PM Rate Topic: -----

#1 Penjos   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-November 19

Why wont this input add to my list

Posted 05 November 2019 - 01:46 PM

I am trying to make a shopping list application but when ever I give my program user input it doesn't add it to my list.
If anyone could give me a hint to why that would be a great help
Thank you in advance!

items = {"test"}
run = 1

while run == 1:

    add = input("What would you like to add?")
    set(items).add(str(add))

    if add == "done":
        break

    if add == "show":
        for f in items:
            print(f) 



Is This A Good Question/Topic? 0
  • +

Replies To: Why wont this input add to my list

#2 Penjos   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-November 19

Re: Why wont this input add to my list

Posted 05 November 2019 - 01:52 PM

I meant set but I cant seem to edit the post
Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 11689
  • View blog
  • Posts: 19,870
  • Joined: 19-March 11

Re: Why wont this input add to my list

Posted 05 November 2019 - 01:54 PM

set(items).add(str(add))



This line makes a new set containing all of the elements in items and adds add to it. This does not affect items

This should work:

items.add(str(add))


Was This Post Helpful? 1
  • +
  • -

#4 Penjos   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-November 19

Re: Why wont this input add to my list

Posted 05 November 2019 - 02:45 PM

View Postjon.kiparsky, on 05 November 2019 - 01:54 PM, said:

set(items).add(str(add))



This line makes a new set containing all of the elements in items and adds add to it. This does not affect items

This should work:

items.add(str(add))



I just thought it made python use it as a set in that instance
Thank you very much this will definetly help me a lot in the future too
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1