954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Python Question: Printing alike prefixes

Hello,
I'm working on a program that would print the prefixes of two user inputs if they matched. I'm thinking of this along the lines of if the value of the first character in a is = to the value of the first character in b, print the value. Next I would say that if the value of the first and second characters in a is the same as the first and second characters in b, print items. I didn't get that far before it collapsed. Anyway this is the code I have so far:

>>> first=raw_input("Please enter the first string")
Please enter the first string
>>> second=raw_data("Please enter the second string")
Traceback (most recent call last):
File "", line 1, in
NameError: name 'raw_data' is not defined
>>> second=raw_input("please enter the second string")
please enter the second string
>>> a = first
File "", line 1
a = first
^
IndentationError: unexpected indent
>>> a=first
>>> b=second
>>>
>>>
>>> if len(b) < len(a)
File "", line 1
if len(b) < len(a)
^
SyntaxError: invalid syntax
>>> if len(b) < len(a):
... a=first
... a=second
... b=first
...
>>> if value 1 in a = value 1 in b
File "", line 1
if value 1 in a = value 1 in b
^
SyntaxError: invalid syntax

beck4456
Newbie Poster
2 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

Use zip function and for loop.

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: