Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 5 Online
OpenStudy (anonymous):

Hello. I'm trying to control the input type of a raw_input from the user. Specifically, I want to allow the user to input a tuple of numbers and have a function evaluate this tuple (by using their positions ...or index). The problem is: no matter what I tell the program the input is..a list..a tuple...a list of floats...it evaluates them as a string. Ex. Me: list(raw_input("tuple?")) User: 1.0, 1.0, 1.0, 1.0, 1.0 If I then print tuple[1] it will return "." because its the second character in this string. Help!

OpenStudy (anonymous):

what version of python are you using? Also, are you wanting the user to imput a float only?

OpenStudy (anonymous):

im not 100% if this is what you are looking for but let me know if it helps. Im on lecture 9 of this course so im not an expert. This should work for ints and floats . I am using python version 2.7.3 numlist = [] numberamount = int(input("how many numbers would you like to enter?")) for i in range(numberamount): if i == 0: numbers = input("Please enter your first number") numlist.append(numbers) elif i > 0: numbers = input("Please enter your next number") numlist.append(numbers) print(numlist)

OpenStudy (anonymous):

Oh I see you want that the user inputs a sequence of numbers in the same line and you evaluate them, right? I'm a python 3.x user so I'll write down the code in this version: # Here we define an empty list for manipulate those numbers (or whatever) numbers_list = [] # Here we ask for the user to input how many objects does want... howmany_numbers = int (input('How many numbers do you want to type?: ')) #Now we make a loop taking the user's input value for i in range (0, howmany_numbers): addnumbers_list = float(input('Type the number: ')) numbers_list.append(addnumbers_list) # and here you can print and do what you want with the information print ('Numbers: ', numbers_list) print ('Lenght: ', len(numbers_list)) print ('Numbers: ', numbers_list[:]) #calling them from index #here you can play around.. min_number = min(numbers_list) max_number = max(numbers_list) print ('Minimum number: ', min_number) print ('Maximum number: ', max_number) #I hope this helps!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Countless7Echos: Ah trying out the whole T.V girl drawing :p (I love drawing eyes)
2 hours ago 13 Replies 6 Medals
kaelynw: starting to draw a hand
11 hours ago 17 Replies 2 Medals
Twaylor: Rate it :D (Took 2 days)
4 days ago 7 Replies 0 Medals
XShawtyX: Art, Short Writing Assignment: Imagining Landscapes
2 days ago 7 Replies 1 Medal
XShawtyX: Chemistry, Help ud83dude4fud83cudffe
5 days ago 13 Replies 1 Medal
kaelynw: tried a lil smt, the arm is off but i like the other stuff
5 days ago 27 Replies 3 Medals
kaelynw: art igg
5 days ago 14 Replies 1 Medal
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!