Why doesn't this code work? i am just trying to slice.(in python) -


when enter code, there error in way slice works...it won't let me enter it, , overall wont work.

verb_1 = raw_input("enter word") verb_2 = verb_1.lower() verb_2_ending = verb_2[-2:] if verb_2_ending == "ar":      ar_verb = raw_input("you've chosen ar verb. tense like") elif verb_2_ending == "er":     er_verb = raw_input("you've chosen er verb. tense like") else :     ir_verb = raw_input("you've chosen ir verb. tense like")  if ar_verb == "subjunctive":     subject_1 = raw_input("what subject") elif  ar_verb == "present":     subject_2 = raw_input("what subject") else :     subject_3 = raw_input("what subject") 

yields error:

enter word : hablar  traceback (most recent call last):  file "<stdin>", line 4, in <module>    typeerror: unsupported operand type(s) -: 'str' , 'str'  

i believe you're looking called slicing not subtraction , in line 3.

it's working okay when run code you've pasted here in idle , because else statements should take care of type errors user input.
can read more on strings , how slicing. try this: http://docs.python.org/release/1.5.1p1/tut/strings.html


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -