Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
input string split
#1
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?
Reply
#2
Which version of Python are you using?
Reply
#3
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)
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using string input for boolean tronic72 3 635 Nov-01-2023, 07:48 AM
Last Post: Gribouillis
  doing string split with 2 or more split characters Skaperen 22 2,317 Aug-13-2023, 01:57 AM
Last Post: Skaperen
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 1,054 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  [split] Parse Nested JSON String in Python mmm07 4 1,413 Mar-28-2023, 06:07 PM
Last Post: snippsat
Question Take user input and split files using 7z in python askfriends 2 1,028 Dec-11-2022, 07:39 PM
Last Post: snippsat
  How to split the input taken from user into a single character? mHosseinDS86 3 1,137 Aug-17-2022, 12:43 PM
Last Post: Pedroski55
  Split string using variable found in a list japo85 2 1,236 Jul-11-2022, 08:52 AM
Last Post: japo85
Big Grin General programming question (input string)[ jamie_01 2 1,569 Jan-08-2022, 12:59 AM
Last Post: BashBedlam
  Split string knob 2 1,840 Nov-19-2021, 10:27 AM
Last Post: ghoul
  Creating new column with a input string drunkenneo 2 2,194 Apr-14-2021, 08:10 AM
Last Post: drunkenneo

Forum Jump:

User Panel Messages

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