Help please, why doesn't it show the next input?

John Gordon gordon at panix.com
Wed Sep 11 01:11:23 EDT 2013


In <ef8de6db-5f35-4d07-8306-bcec47b1e69b at googlegroups.com> William Bryant <gogobebe2 at gmail.com> writes:

> Hey, I am very new to python, I am 13 years old. I want to be able to make =
> a program the caculates the mean, meadian and mode. When i run the program,=
>  an input field pops up and says 'Does your list contain, a number or a str=
> ing?' like I want it to, but when I type in something that is not one of va=
> lid field options: "String" or "string" or "STRING" or "s" or "S" or "str" =
> or "Number" or "number" or "NUMBER" or "N" or "N" or "int" or "num", nothin=
> g happens, please tell me what I did wrong. Thanks :D Here is my code:

> #-----           Variables that I am using, including the list.          --=
> ---#

> #False means num
> #True means string
> num_or_string =3D ""
> amount_numbers =3D []
> List =3D []
> I =3D "Does your list contain, a number or a string?"

> #-----                      Functions that I am using.                    -=
> ----#
> input(I)

> def NOS():
>     if I =3D=3D "String" or "string" or "STRING" or "s" or "S" or "str":
>         pass
>     elif I =3D=3D "Number" or "number" or "NUMBER" or "N" or "N" or "int" o=
> r "num":
>         pass
>     else:
>         global I
>         I =3D "You did not enter a valid field, :P Sorry."
>         input(I)

First of all, you haven't given us your whole program.  I know this because
while you've defined the NOS function, it isn't actually called anywhere.
You must have left that part out.

Anyway, I think you're doing two things wrong:

1. You aren't capturing the user's input.  The input() function returns
the user's input, but you aren't assigning this to a variable; it's just
being thrown away.  You should call input() like this:

  user_input = input(I)

(Also, it would probably be clearer to use a name like "prompt" instead
of "I".)

2. You aren't using the compound "if" statement correctly.  You can't
   do this (well, you CAN, but it won't do what you want):

       if a == 1 or 2 or 3:

   You should fully spell out each condition, like this:

       if a == 1 or a == 2 or a == 3:

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list