473,549 Members | 3,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

appending user entered items to array, then displaying them

3 New Member
OK, so I am trying to make a shopping list which appends each item entered to an array until the user enters "0"
I have got this far and it just doesnt work :-(
Would really appreciate some suggestions or pointers!
Thanks very much!

Expand|Select|Wrap|Line Numbers
  1. ShopList = [] 
  2. ListItem= ()
  3. print("To make a shopping list")
  4. print("Enter the items, when you have finished press 0 to display the list.")
  5. while ListItem != 0:
  6.     ListItem = input ("Enter your Item to the List: ")
  7.     ShopList.append(ListItem)
  8. print ("Here's your Shopping List:")
  9. for item in ShopList:
  10.     print item
Jun 19 '14 #1
3 1339
dwblas
626 Recognized Expert Contributor
The answer depends on whether you are using Python 2.x or 3.x. Your program will work in 2.x but will not in 3.x because of a difference in way the input() function is programmed. Print the type of the item entered after the input statement. If the type is string then comparing list_item to the integer zero will never be true because they are different types. So the answer to this overly long explanation is if you are using Python 3, and the use of print as a function suggests you are, then compare to "0", a string, instead of 0 an integer. Also, note that the Python Style Guide prefers variable names that are all lower case with underlines. CamelCase is for classes. This convention helps others read and understand your code, especially when it gets more complex.
Expand|Select|Wrap|Line Numbers
  1. while list_item != "0":  ## Note the quotes
  2.      list_item = input ("Enter your Item to the List: ")
  3.      print(type(list_item)) 
Jun 19 '14 #2
blackpaddycat
3 New Member
Ah, Thanks very much dwblas, and also for the reference to the style guide as well. V new to python, and indeed programming.
Have now got the code working for 2.7 and 3.3.
Feeling pleased rather than frustrated. Not very good at this programming malarky!
Jun 19 '14 #3
dwblas
626 Recognized Expert Contributor
The best way to start is with one of the tutorials https://wiki.python.org/moin/BeginnersGuide/Programmers
Jun 20 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
7309
by: Gregory | last post by:
Hello, I've managed to build two web pages, one that can display images with associated text data in a table, and one that can resize and display images without the text. I'd like to resize the images as I go, without writing them to disk on the server. Do I need to prepare all of the resized images before I display the data from the select...
13
9272
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and three dropdow boxes for hours, minutes, and AM/PM. All of these need to be considered together and converted to one Unix Timestamp and then inserted...
0
1192
by: emer.kurbegovic | last post by:
I need to build a filter that will filter user entered html and which will allow only certain html tags through (i.e. <IMG>, <SCRIPTand <EMBEDwould be allowed). i was going to HtmlEncode the entire user html input and filter out only what is "allowed". i need the best way to filter for all possible known xss attacks. is there anything...
0
1062
by: tenko | last post by:
here's a question regarding changing units, say from g to kg without changing the entire codes.... my mathematical equation uses KG (kilograms), but the user can choose whether to enter values in G or KG. if the user entered the option in G, how can i convert from the string "KG" to "G" for every of the term in console.writeline that i do...
9
2375
by: Anneybo | last post by:
Alright, I give up! I'm asking the experts. I have created a database that calculates PTO for employees. I need to be able to cache the report by user entered dates and specific employee names. I have been able to get the dates to work with the following VBA script: .. Private Sub cmdOK_Click() Dim strReport As String 'Name of report...
0
1465
by: dgs | last post by:
How to scan the user-entered value ? like, we have "scanf()" in 'C'.......
8
6018
by: unkietee | last post by:
Hi Experts, my first post here! I hope you can help me. I have a basic form which I want the user to enter either a number (postcode/zipcode) or text (suburb). When they hit submit I want to check what has been entered and then send them to either a postcode/zip code page if it was a number entered or send them to a suburb page if it was...
4
4148
by: ghjk | last post by:
I want to compare user entered date with data base datetime value. Database value in datetime type and first i want to extract date part and then compare with user entered value. This is my query. Could someone tell me what is wrong with it? SELECT * FROM db WHERE Date = SELECT CAST(Date AS DATE) AS dateonly FROM db
2
1285
by: gilly1471 | last post by:
Yep, new to perl, I started yesterday, but am quickly excelling. I would just like to know how to use user entered data. Let's say I have a programm that calculates the circumference of a circle. The user has to enter in the radius of the circle and then the units of measurement. If the user enters his data into an html page that directs the...
3
1694
by: rhonda2010 | last post by:
My project consists of a user interface designed in Visual Studio 2010 Express. I have it linked to an Access database. At this time, I have two text boxes that the user will enter a number. I want to be able to write a query that will take the first and second number and pull the information from the database that is equal to or greater than...
0
7520
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7718
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1936
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.