473,383 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to use a for loop to print a list of salespeople with their individual sales

My program is supposed to output a list of users who input their sales name along with their sales amount and then print out a display. I am using a nested for loop to read through the list of salespeople along with their sales amounts. The problem is that my for loops keep printing out the salesperson along with the sales of other users...

Expand|Select|Wrap|Line Numbers
  1. for sale in range(len(salesAmounts)):
  2.     for name in range(len(newSalesPerson)):
  3.         label = str(1 + name) + '.'
  4.         print 'Sales Person: ', label + newSalesPerson[name] + ' Sales: ',  salesAmounts[sale]
  5.  
This is the output:

Enter Sales Person: (Press ENTER to quit) reg
Enter the sales amount: 600
Enter Sales Person: (Press ENTER to quit) tee
Enter the sales amount: 300
Enter Sales Person: (Press ENTER to quit) mark
Enter the sales amount: 200
Enter Sales Person: (Press ENTER to quit)
===========================================
===========================================
Sales Person: 1.reg Sales: 600
Sales Person: 2.tee Sales: 600
Sales Person: 3.mark Sales: 600
Sales Person: 1.reg Sales: 300
Sales Person: 2.tee Sales: 300
Sales Person: 3.mark Sales: 300
Sales Person: 1.reg Sales: 200
Sales Person: 2.tee Sales: 200
Sales Person: 3.mark Sales: 200
Oct 17 '10 #1
1 1676
bvdet
2,851 Expert Mod 2GB
Try something like this:
Expand|Select|Wrap|Line Numbers
  1. for i, name in enumerate(newSalesPerson):
  2.     print 'Sales Person: %s  Sales: %s', % (name, salesAmounts[i])
There should not be a nested loop.
Oct 18 '10 #2

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

Similar topics

19
by: Jim | last post by:
Where did this type of structure come from: mat = ? This will produce a list of three elements but I don't see reference for it in any of the books.
4
by: marcelf3 | last post by:
Hello, I am a novice/moderate html programmer and I wonder how to tell the browser from which start point and to which end point in the text will each page be printed. In other words, I have a...
5
by: Nick Calladine | last post by:
Learning : Loop to list all dropdown box values on a form Can some one point me in the right direction : I have a form which I want to loop through I basically want to get all the selected...
5
by: author | last post by:
How can I do the below classic ASP in .NET ?? - I have tried using a repeater, but can only get one long list, in my ex. I need a list (contains 3 list) TIA --- Some data for the...
12
by: Danny | last post by:
Hello there. I'm creating a little text changer in Python. In the program there is a while loop. The problem is that a while loop will have 1 print statement and it will loop until it gets to...
0
by: Bob | last post by:
I need to print a list of .PDF documents in the order that they are submitted. Previously the print queue has taken the documents in an arbitrary order. Does anyone have .NET code that will force...
10
by: s.lipnevich | last post by:
Hi All, I apologize if this was brought up before, I couldn't find any "prior art" :-). On more than one occasion, I found myself wanting to use a "conditional loop" like this (with "Invalid...
19
by: bvdp | last post by:
Please help my poor brain :) Every time I try to do a list comprehension I find I just don't comprehend ... Anyway, I have the following bit of code: seq = tmp = for a in range(len(seq)):...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.