Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
input string split
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.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating new column with a input string drunkenneo 2 586 Apr-14-2021, 08:10 AM
Last Post: drunkenneo
  Python win32api keybd_event: How do I input a string of characters? JaneTan 3 861 Oct-19-2020, 04:16 AM
Last Post: deanhystad
  Split string between two different delimiters, with exceptions DreamingInsanity 2 734 Aug-24-2020, 08:23 AM
Last Post: DreamingInsanity
  split string enigma619 1 688 May-20-2020, 02:47 PM
Last Post: perfringo
  Split string with multiple delimiters and keep the string in "groups" DreamingInsanity 4 2,017 May-12-2020, 09:31 AM
Last Post: DeaD_EyE
  Split and sort input file aawaleh 4 1,241 Apr-10-2020, 09:59 PM
Last Post: aawaleh
  Split a long string into other strings with no delimiters/characters krewlaz 4 1,082 Nov-15-2019, 02:48 PM
Last Post: ichabod801
  with input remove a string from the list konsular 3 1,089 Oct-12-2019, 09:25 AM
Last Post: konsular
  [split] capitalize dict keys for display in string newbieAuggie2019 3 1,213 Oct-10-2019, 10:50 AM
Last Post: perfringo
  How to split string after delimiter SriRajesh 1 887 Sep-11-2019, 11:25 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020