Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 03-29-2008, 04:08 AM   #1 (permalink)
sinci's Avatar
 
Super Techie

Join Date: Jan 2006

Location: Perth, Australia

Posts: 328

sinci is on a distinguished road

Default IDLE help.

Well, for school, we're still using Python and so I'm real new at it.
but; is there anyway I can put the bolded part of the code below, into a smaller piece of code?
I've heard of a loop or something?
Sorry I'm a noob. :|
but thanks xD

Oh, and the letters like, t and z etc will be changed, they're just there because I needed them quickly


def calc_check_digit(number):
number=str(number)
a=number[-1]
b=number[-2]
c=number[-3]
d=number[-4]
e=number[-5]
f=number[-6]
g=number[-7]
h=number[-8]
i=number[-9]
j=number[-10]
k=number[-11]
l=number[-12]
m=number[-13]
n=number[-14]
o=number[-15]
p=number[-16]
a=a
b=b*2
c=c
d=d*2
e=e
f=f*2
g=g
h=h*2
i=i
j=j*2
k=k
l=l*2
m=m
n=n*2
o=o
p=p*2

if number > 9:
number=int(number)
number - 9
z=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p
z=int(number)
t=z % 10
print t
__________________


InfernoDeals

92% of teens have moved on to rap. If you are part of the 8% who listen to real music, copy this.


If you're someone who has faith that Mike has the strength to win this battle copy this to your sig.
Some girl I know: im on a wireless network so i cant find my router
Sylus: The thing with numbers on it is my binary blanket.
sinci is offline  
Old 03-29-2008, 06:22 AM   #2 (permalink)
Apokalipse's Avatar
 

Join Date: Jun 2003

Location: Melbourne, Australia

Posts: 13,739

Apokalipse has a spectacular aura aboutApokalipse has a spectacular aura about

Default Re: IDLE help.

I haven't learned python, but:
b = a-1
c = a-2
etc..
__________________

1 + 1 = 3 if you define 3 as a result of 1 + 1
Apokalipse is offline  
Old 03-29-2008, 08:15 AM   #3 (permalink)
sinci's Avatar
 
Super Techie

Join Date: Jan 2006

Location: Perth, Australia

Posts: 328

sinci is on a distinguished road

Default Re: IDLE help.

That wouldn't work

The [-1] [-2] [-3] etc, is the letter of the string, like..character value? or something.

So if I had a word that said "alphabet" and called it x, so x=alphabet.

z=x[0] would make z equal the a in alphabet.
z=x[1] would make z equal the p in alphabet.
z=[-1] would make z equal the t in alphabet.
That's a quick python lesson :| from a noob. I doubt it made sense.

Anyway,

Thanks for trying =D
__________________


InfernoDeals

92% of teens have moved on to rap. If you are part of the 8% who listen to real music, copy this.


If you're someone who has faith that Mike has the strength to win this battle copy this to your sig.
Some girl I know: im on a wireless network so i cant find my router
Sylus: The thing with numbers on it is my binary blanket.
sinci is offline  
Old 03-29-2008, 08:13 PM   #4 (permalink)
S0ULphIRE's Avatar
 
01001100011011110110110

Join Date: Mar 2007

Location: Perth, Australia

Posts: 2,001

S0ULphIRE has a spectacular aura aboutS0ULphIRE has a spectacular aura about

Send a message via MSN to S0ULphIRE
Default Re: IDLE help.

For a start, you don't need to include parts like e=e and a=a, that cuts you down 8 lines.
As for the first A-P definitions line, you'll have to keep it like that anyway, a loop wouldn't work because you have to define the variables.
There might be a way to cut down the *2 bits, I'll think about it and get back to you if I get anything
__________________
"As a result of all this hardship, dirt, thirst, and wombats, you would expect Australians to be a dour lot. Instead, they are genial, jolly, cheerful, and always willing to share a kind word with a stranger, unless they are an American."
-- Douglas Adams

Click this if I helped you
>>>><<<<
S0ULphIRE is offline  
Old 03-29-2008, 10:01 PM   #5 (permalink)
sinci's Avatar
 
Super Techie

Join Date: Jan 2006

Location: Perth, Australia

Posts: 328

sinci is on a distinguished road

Default Re: IDLE help.

Good Point =D

Thanks,

Oh, and if you're curious...
It's part of a program to find out a IBM Check Digit
__________________


InfernoDeals

92% of teens have moved on to rap. If you are part of the 8% who listen to real music, copy this.


If you're someone who has faith that Mike has the strength to win this battle copy this to your sig.
Some girl I know: im on a wireless network so i cant find my router
Sylus: The thing with numbers on it is my binary blanket.
sinci is offline  
Old 03-30-2008, 12:02 AM   #6 (permalink)
S0ULphIRE's Avatar
 
01001100011011110110110

Join Date: Mar 2007

Location: Perth, Australia

Posts: 2,001

S0ULphIRE has a spectacular aura aboutS0ULphIRE has a spectacular aura about

Send a message via MSN to S0ULphIRE
Default Re: IDLE help.

I took a look at the IBM thing, why are you assigning each individual number a variable?
Try assigning the whole string of numbers (e.g. 6234 6243 2093 1029) one variable, say 'number'.
I'll just work on the code and post back if it works (i has got an idea!)
__________________
"As a result of all this hardship, dirt, thirst, and wombats, you would expect Australians to be a dour lot. Instead, they are genial, jolly, cheerful, and always willing to share a kind word with a stranger, unless they are an American."
-- Douglas Adams

Click this if I helped you
>>>><<<<
S0ULphIRE is offline  
Old 03-30-2008, 12:49 AM   #7 (permalink)
Apokalipse's Avatar
 

Join Date: Jun 2003

Location: Melbourne, Australia

Posts: 13,739

Apokalipse has a spectacular aura aboutApokalipse has a spectacular aura about

Default Re: IDLE help.

in Java, there are shortcuts to adding, dividing, multiplying or subtracting from a variable. I don't know if Python has something equivalent.

a = a * 2;
is the same as
a *= 2;

same with other operations
a += 2;
a -= 2;
a /= 2;
a %= 2;

or there's operations like
a++; increases a by 1
a--; decreases a by 1
__________________

1 + 1 = 3 if you define 3 as a result of 1 + 1
Apokalipse is offline  
Old 03-30-2008, 12:57 AM   #8 (permalink)
S0ULphIRE's Avatar
 
01001100011011110110110

Join Date: Mar 2007

Location: Perth, Australia

Posts: 2,001

S0ULphIRE has a spectacular aura aboutS0ULphIRE has a spectacular aura about

Send a message via MSN to S0ULphIRE
Default Re: IDLE help.

same with C, but I don't think python has those.
Ok, update. Basically what I tried was:
number=[5,1,3,2,4,5,6,7,2,3,4,5,6,4,5,6]
number1=number[1]*2,number[3]*2 etc.
the stuff-up came when I tried checking (and taking away) 9 from the values.
__________________
"As a result of all this hardship, dirt, thirst, and wombats, you would expect Australians to be a dour lot. Instead, they are genial, jolly, cheerful, and always willing to share a kind word with a stranger, unless they are an American."
-- Douglas Adams

Click this if I helped you
>>>><<<<
S0ULphIRE is offline  
Old 03-30-2008, 02:47 AM   #9 (permalink)
sinci's Avatar
 
Super Techie

Join Date: Jan 2006

Location: Perth, Australia

Posts: 328

sinci is on a distinguished road

Default Re: IDLE help.

No, python doesn't.

and it uses += as not equal to, aswell as !=
__________________


InfernoDeals

92% of teens have moved on to rap. If you are part of the 8% who listen to real music, copy this.


If you're someone who has faith that Mike has the strength to win this battle copy this to your sig.
Some girl I know: im on a wireless network so i cant find my router
Sylus: The thing with numbers on it is my binary blanket.
sinci is offline  
Old 03-30-2008, 02:49 AM   #10 (permalink)
sinci's Avatar
 
Super Techie

Join Date: Jan 2006

Location: Perth, Australia

Posts: 328

sinci is on a distinguished road

Default Re: IDLE help.

Oh, I'm assigning each individual character because I need to multiply every second number by 2. not the whole string.

I've tried with this method as well, but I can't make the second number add the units together.

MSI Barcode - Wikipedia, the free encyclopedia
__________________


InfernoDeals

92% of teens have moved on to rap. If you are part of the 8% who listen to real music, copy this.


If you're someone who has faith that Mike has the strength to win this battle copy this to your sig.
Some girl I know: im on a wireless network so i cant find my router
Sylus: The thing with numbers on it is my binary blanket.
sinci is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to setup win2k3 users account idle timout linux1880 Computer Networking & Internet Access 10 03-31-2008 07:30 PM
Idle load difference san21893 Building, Buying, or Upgrading High Performance PC Systems 7 08-25-2007 01:42 PM
idle temp Nick Overclocking, Case Mod, Tweaking PC Performance 13 08-16-2007 12:06 PM
Up/down-load without reason when idle socbar Windows Operating Systems and Software 3 08-03-2007 07:09 AM
E6600 Idle temps STATus h2O Overclocking, Case Mod, Tweaking PC Performance 3 04-02-2007 09:11 AM