[Tutor] trouble with if
Aditya Lal
aditya.n.lal at gmail.com
Fri Oct 26 08:35:59 CEST 2007
I think you need to use "raw_input" instead of "input". input "eval" the
input expression while "raw_input" just stores it. I find the module help
very handy when I am in doubt.
>>> print raw_input.__doc__
raw_input([prompt]) -> string
Read a string from standard input. The trailing newline is stripped.
If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
On Unix, GNU readline is used if enabled. The prompt string, if given,
is printed without a trailing newline before reading.
>>> print input.__doc__
input([prompt]) -> value
Equivalent to eval(raw_input(prompt)).
On 10/26/07, Bryan Fodness <bryan.fodness at gmail.com> wrote:
>
> I cannot get this to work either.
>
> woffaxis = 7
>
> if woffaxis != 0:
> woaf_pos = input("What is Wedge Direction (N/A, Lateral, Towards
> Heal, Towards Toe)?")
>
> if woaf_pos == 'Towards Toe':
> woffaxis = woffaxis
> elif woaf_pos == 'Towards Heal':
> woffaxis = (woffaxis * -1)
> else:
> woffaxis = 0
>
>
>
>
>
>
> On 10/24/07, John Fouhy <john at fouhy.net> wrote:
> >
> > On 25/10/2007, Bryan Fodness <bryan.fodness at gmail.com> wrote:
> > > I have the following code, it keeps giving me a value of 1 for e.
> > >
> > > for line in file('21Ex6MV_oaf.dat'):
> > > oa, openoa, w15, w30, w45, w60 = line.split()
> > > if (float(oa) == round(offaxis)) and (eff_depth < 10 and
> > unblockedFS >
> > > 15):
> > > e = float(openoa)
> > > else:
> > > e = 1
> > >
> > > If I comment out the else, I get the correct value
> > >
> > > for line in file('21Ex6MV_oaf.dat'):
> > > oa, openoa, w15, w30, w45, w60 = line.split()
> > > if (float(oa) == round(offaxis)) and (eff_depth < 10 and
> > unblockedFS >
> > > 15):
> > > e = float(openoa)
> > > # else:
> > > # e = 1
> >
> > Maybe you need a 'break' statement after 'e = float(openoa)'?
> >
> > As written, e will have whatever value is appropriate for the last
> > line of your input file.
> >
> > --
> > John.
> >
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Aditya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071026/6bba5fb8/attachment.htm
More information about the Tutor
mailing list