Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 39 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
YoungBlood: pfp wonu2019t let me switch
21 minutes ago 0 Replies 0 Medals
Austinsbabygirl4life: Do you think guys would survive on periods?
2 hours ago 22 Replies 2 Medals
alyviahwillis: if anyone has any questions feel free to DM me... I don't mind at all.
4 hours ago 0 Replies 0 Medals
Rosee5656: how do I level up!??!? >,
3 hours ago 14 Replies 4 Medals
Abby13915: I made an alpaca for my fashion club
8 hours ago 3 Replies 0 Medals
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!