Flag control variable

L

luke.geelen

hey, i got another problem now,
if i use the imterpreter to do 3 * 4 it gives twelve
the script gives 3333?
any tips
 
G

Gary Herron

hey, i got another problem now,
if i use the imterpreter to do 3 * 4 it gives twelve
the script gives 3333?
any tips
12
'3333'


Multiplying two integers produces the result you expect.

Multiplying a *string* by an integer is what you are doing. (And it just
repeats the string a number of times -- not what you want.)

Your code used to have int(...) to convert the string supplied by
sys.argv into integers. What happened to them?

Gary Herron
 
L

luke.geelen

Would it be possible to make an
int(sys.argv[1])
Not needed and set value 0 ( or in another script 1)
For example
a = int(sys.argv[1])
b = int(sys.argv[2])
c = int(sys.argv[3])
And I run
Python ./script.py 2 3

It just set c automaticly to 0 or 1

Luke

(PS thanks for the quick help)
 
G

Gary Herron

Would it be possible to make an
int(sys.argv[1])
Not needed and set value 0 ( or in another script 1)
For example
a = int(sys.argv[1])
b = int(sys.argv[2])
c = int(sys.argv[3])
And I run
Python ./script.py 2 3

It just set c automaticly to 0 or 1

Luke

(PS thanks for the quick help)

That question does not make sense to me. Yes, you can set c=1 in your
program, or zero if that's what you want, but this can't be the question
you are really trying to ask.
 
L

luke.geelen

Can I make it that if
C = int(sys.argv[3])
But when I only enter 2 argumentvariable it sets c automaticly to 0 or 1
 
D

Dave Angel

Can I make it that if
C = int(sys.argv[3])
But when I only enter 2 argumentvariable it sets c automaticly to 0 or 1

Why do you ask for 'automatically'? You're the programmer, write
the test in the code.

if len (sys.argv) == 3:
sys.argv. append ("0")

But of course there are lots of other things you need to check,
so consider all of them at the same time.
 
L

luke.geelen

Op woensdag 12 februari 2014 06:23:14 UTC+1 schreef Dave Angel:
Can I make it that if
C = int(sys.argv[3])
But when I only enter 2 argumentvariable it sets c automaticly to 0 or 1



Why do you ask for 'automatically'? You're the programmer, write

the test in the code.



if len (sys.argv) == 3:

sys.argv. append ("0")



But of course there are lots of other things you need to check,

so consider all of them at the same time.

then i keep getting IndexError: list index out of range
anyway to prevent it and just set the value to 0?
 
M

Mark Lawrence

Op woensdag 12 februari 2014 06:23:14 UTC+1 schreef Dave Angel:
Can I make it that if
C = int(sys.argv[3])
But when I only enter 2 argumentvariable it sets c automaticly to 0 or 1



Why do you ask for 'automatically'? You're the programmer, write

the test in the code.



if len (sys.argv) == 3:

sys.argv. append ("0")



But of course there are lots of other things you need to check,

so consider all of them at the same time.

then i keep getting IndexError: list index out of range
anyway to prevent it and just set the value to 0?

Please find a semi-decent tool to use or always follow the instructions
for how to remove the double line spacing when using gg, thanks.
 
A

Alain Ketterlin

Can I make it that if
C = int(sys.argv[3])
But when I only enter 2 argumentvariable it sets c automaticly to 0 or 1

C = int(sys.argv[3]) if len(sys.argv) > 3 else 0

is one possibility.

-- Alain.
 
D

Dave Angel

Deleting all the obnoxious doublespaced googlegroups nonsense. ..
then i keep getting IndexError: list index out of range
anyway to prevent it and just set the value to 0?

My car makes a funny noise. What kind of
coat should I wear to
the dance to fix it? And do I turn left or back up at the
corner?
 
D

Dennis Lee Bieber

Can I make it that if
C = int(sys.argv[3])
But when I only enter 2 argumentvariable it sets c automaticly to 0 or 1

I suspect it will be beyond your current skill level, but you are
rapidly approaching the point where you might want to study the
documentation for the argparse module (or the earlier optparse module --
it's a steeplechase... getopt losing out to optparse which in turn loses to
argparse))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,616
Members
45,306
Latest member
TeddyWeath

Latest Threads

Top