Jump to content

Having Issues in Python, Just Started, Would Like Some Assistance

EChondo
Go to solution Solved by MikeD,


for i in range(1, 20):

print("NV-CART01-%02d" % i)

So I've been interested in doing some simple coding for generating lists of various items. I've recently had to create a list of labels used to label some school laptops. Since we have around 500+ laptops distributed among schools, we have to keep them organized. I do not know anything about coding and have just started reading up on it and trying to wrap my head around it, currently I'm trying to automate the generating list process, but I'm having difficulties getting started.
 
The labels need to be SCHOOL-CART#-Laptop#. We are using acronyms for the school and have to use two digit numbering.
 
Example; AZ-CART01-01.
 
The laptop number can't exceed 20 because that is how much a single cart can hold. I have to do this for various amounts of carts for different schools. So once I get to AZ-CART01-20 I have to start a new cart, so AZ-CART02-01. Then when I get done with the amount of laptop carts I need, I go on to the next school.
 
Example; NV-CART01-01.
 
The code I have so far(experimenting really) is;

SchoolSite = input("What is the school site?")print(SchoolSite) if(SchoolSite == "Arizona"):    print("AZ-CART01-(list(range(01, 20)))")if(SchoolSite == "NorteVista"):    print("NV-CART01-(list(range(01, 20)))")

&

SchoolSite = input("What is the school site?")print(SchoolSite)if(SchoolSite == "Arizona"):    print("AZ-CART01-(range(01, 20))")if(SchoolSite == "NorteVista"):    print("NV-CART01-(range(01, 20))")

But I end up with this;
LszSOJY.png
 
I know I am doing something wrong, but I am not sure what. If someone could give me some solution I'd be most appreciative. I have been reading on lists and ranges for over a hour now and I'm pretty stumped, either I am not understanding or I am setting it up wrong.

 

*Edit, just saw that "print" is overriding the list and range, is there some way I could force it to allow list and/or range?

Link to comment
Share on other sites

Link to post
Share on other sites

Don't include this (range(01, 20)) in between the " " and separate it like so..

 

print("NV-CART01", -(range(01, 20)))

 

although I don't think that will work either, it's just an example.

 

 

p.s I just skimmed your post so sorry if it isn't what you wanted.

Link to comment
Share on other sites

Link to post
Share on other sites

Don't include this (range(01, 20)) in between the " " and separate it like so..

 

print("NV-CART01", -(range(01, 20)))

 

although I don't think that will work either, it's just an example.

 

 

p.s I just skimmed your post so sorry if it isn't what you wanted.

It's not a problem. I need it to print NV-CART01-01 all the way to NV-CART01-20. The way you suggested only creates a list like NV-CART01- [1, 2, 3, etc.].

 

Not exactly, but I am having some fun figuring this out haha.

Link to comment
Share on other sites

Link to post
Share on other sites

It's not a problem. I need it to print NV-CART01-01 all the way to NV-CART01-20. The way you suggested only creates a list like NV-CART01- [1, 2, 3, etc.].

 

Not exactly, but I am having some fun figuring this out haha.

you could create a for loop that prints NV-CART n for all n from 1 to 20.

for i in range(1,20):    print("NV-CART",i)

In Python 3 I think.

Link to comment
Share on other sites

Link to post
Share on other sites

print("AZ-CART{:02d}-{:02d}".format(cart#,laptop#))

 

put that into a loop, incrementing laptop#. If laptop number is > 20, set it to 1 and add 1 to cart#

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

you could create a for loop that prints NV-CART n for all n from 1 to 20.

for i in range(1,20):    print("NV-CART",i)

In Python 3 I think.

This almost worked.

SchoolSite = input("What is the school site?")print(SchoolSite)if(SchoolSite == "Arizona"):    print("AZ-CART01-(list(range(01, 20)))")if(SchoolSite == "NorteVista"):    for i in range(1, 21):        print("NV-CART01-",i)

Result;

 

v2zunCi.png

 

I have two problems. There can't be a space between "CART01-" and the number, and I would like to have it listed as 01, 02, 03, etc. until 10, 11, 12, etc.

 

I'll play around with this some more, really appreciate it guys!

 

*Edit, it appears in Python 3 octal numbers are handled differently than in Python 2, I'll see if I can find a workaround.

Link to comment
Share on other sites

Link to post
Share on other sites

for i in range(1, 20):  print("NV-CART01-%02d" % i)

And this is the solution(although I had to set it to 21, not 20, it stops at 19 when set to 20). Many thanks!

 

Finished code;

SchoolSite = input("What is the school site? ")print(SchoolSite)if(SchoolSite == "Arizona"):    for i in range(1, 21):        print("AZ-CART01-%02d" % i)        print("AZ-CART02-%02d" % i)        print("AZ-CART03-%02d" % i)        print("AZ-CART04-%02d" % i)if(SchoolSite == "Norte Vista"):    for i in range(1, 21):        print("NV-CART01-%02d" % i)        print("NV-CART02-%02d" % i)        print("NV-CART03-%02d" % i)        print("NV-CART04-%02d" % i)        print("NV-CART05-%02d" % i)        print("NV-CART06-%02d" % i)if(SchoolSite == "Villegas"):    for i in range(1, 21):        print("YV-CART01-%02d" % i)        print("YV-CART02-%02d" % i)        print("YV-CART03-%02d" % i)        print("YV-CART04-%02d" % i)if(SchoolSite == "La Sierra"):    for i in range(1, 21):        print("LS-CART01-%02d" % i)        print("LS-CART02-%02d" % i)        print("LS-CART03-%02d" % i)        print("LS-CART04-%02d" % i)        print("LS-CART05-%02d" % i)        print("LS-CART06-%02d" % i)if(SchoolSite == "Loma Vista"):    for i in range(1, 21):        print("LV-CART01-%02d" % i)        print("LV-CART02-%02d" % i)        print("LV-CART03-%02d" % i)        print("LV-CART04-%02d" % i)

Result for Villegas;

C7ikWDo.png

 

Many thanks guys. It's been fun experimenting with this! Now I'll read up on percentages :P

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×