Bottom Page

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.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Split a long string into other strings with no delimiters/characters krewlaz 4 111 Nov-15-2019, 02:48 PM
Last Post: ichabod801
  with input remove a string from the list konsular 3 155 Oct-12-2019, 09:25 AM
Last Post: konsular
  [split] capitalize dict keys for display in string newbieAuggie2019 3 233 Oct-10-2019, 10:50 AM
Last Post: perfringo
  How to split string after delimiter SriRajesh 1 122 Sep-11-2019, 11:25 AM
Last Post: metulburr
  [split] NameError: name 'lo' is not defined when using input ? Cedmo 2 432 Jul-05-2019, 09:39 PM
Last Post: Cedmo
  simple string & input problem kungshamji 5 383 Jun-23-2019, 03:54 PM
Last Post: kungshamji
  How to use a string method on user input Exsul 2 409 Mar-17-2019, 08:12 PM
Last Post: Exsul
  split string and keep separator wardancer84 2 521 Nov-21-2018, 11:20 AM
Last Post: wardancer84
  How to reliably split string containing multiple sqlite statements? shanepy 2 491 Nov-21-2018, 12:07 AM
Last Post: shanepy
  Mixed string,Integer input variable issue maderdash 2 484 Nov-06-2018, 09:46 AM
Last Post: snippsat

Forum Jump:

Users browsing this thread: 1 Guest(s)