Python Forum

Full Version: input string split
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello. Self-teaching and new to Python. I am trying to code a program where I ask a user for 2 points and attempt to calculate the distance. I keep running into errors when I try to take the inputted string, seperated by commas, and split them into the list.

For example, the question and input from the user is:
Quote:Enter x1 and y1 for Point 1: 1.9, -2.4
Enter x2 and y2 for Point 2: 5, 6
This is the code I have so far:
import math
import string
from string import split    

[quote]x_input = input("Enter x1 and y1 for Point 1: ")
y_input = input("Enter x2 and y2 for Point 2: ")

x = split(x_input, ",")

print (x[1])
The error I keep getting is "AttributeError: 'tuple' object has no attribute 'split'".

Any help?
Which version of Python are you using?
I am using version 2.7

As you asked that, I looked to see that split() isn't needed in python 2.7. However, when I worked on this some more, if I input 12 and
print (x_input[1])
just the 2 prints. How do I reference the whole number 12 (rather it is 12 or 1200)
In python 2.7 you need to use raw_input() instead of input() which is another function. That said you shouldn't be using python 2.7 if you want to learn python because you are going to learn an obsolete language that will retire in less than two months.

Use python 3.