On Wednesday, September 11, 2013 5:11:23 PM UTC+12, John Gordon wrote: > In <ef8de6db-5f35-4d07-8306-bcec47b1e...@googlegroups.com> William Bryant > <gogobe...@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 > > gor...@panix.com B is for Basil, assaulted by bears > > -- Edward Gorey, "The Gashlycrumb Tinies"
Thanks so much for putting your time into helping me!! It worked! Could you tell me if I did anything wrong this time? :) #----- Variables that I am using, including the list. -----# num_or_string = "" amount_numbers = [] List = [] prompt = "Does your list contain, a number or a string?" #----- Functions that I am using. -----# user_input1 = input(prompt) user_input1 def NOS(): if user_input1 == "String" or user_input1 == "string" or user_input1 == "STRING" or user_input1 == "s" or user_input1 == "S" or user_input1 == "str": print("a") elif user_input1 == "Number" or user_input1 == "number" or user_input1 == "NUMBER" or user_input1 == "N" or user_input1 == "N" or user_input1 == "int" or user_input1 == "num": print("a") else: global user_input2 global prompt prompt = "You did not enter a valid field, :P Sorry." user_input2 = input(prompt) user_input2 NOS2() def NOS2(): if user_input2 == "String" or user_input2 == "string" or user_input2 == "STRING" or user_input2 == "s" or user_input2 == "S" or user_input2 == "str": print("a") elif user_input2 == "Number" or user_input2 == "number" or user_input2 == "NUMBER" or user_input2 == "N" or user_input2 == "N" or user_input2 == "int" or user_input2 == "num": print("a") else: global user_input2 global prompt prompt = "You did not enter a valid field, :P Sorry." user_input2 = input(prompt) user_input2 NOS2() NOS() -- https://mail.python.org/mailman/listinfo/python-list