I have a string s="expences > drinks"
that is sent to a function. Inside that function I am supposed to add new values using raw_input()
till I input an empty string.
Each one of these inputs should be added to the initial string. In the case of an empty string, the function must return the string with all of the previously added words.
I tried to realize it by calling the function from itself and pass it the changed string but it just returns with only the first added word. I also tried avoid calling the function from itself using while True:
and if empty string then break the loop and return the value. But none of these variants works properly.
Please explain what I do wrong and what is the most pythonic way of doing this.
Here's the code:
#!/usr/bin/env python -tt
# -*- coding: utf-8 -*-
def create_sub_cat(parent):
print "creating subcat\n %s > " %(parent)
conf=raw_input("type new subcat or press \"ENTER\" to save changes\n")
if conf!="":
parent+=" > "+conf
create_sub_cat(parent)
return parent
s="expences > drinks"
print create_sub_cat(s)