Hey everyone, I am a beginner at python, and on these forums (even though I have lurked here quite a bit). Anyway, I really need some help with recursive functions. I don't exactly know how they work, and I have to be able to answer the following questions:

Turn a line of input containing matching pairs of round (()) or curly ({}) brackets into a mountain range. The height of the mountain should indicate how deeply nested the brackets are.

For example, given this input:


Your program should output:

   (){}()  (){}()    (){}()  (){}()    (){}()  (){}()
  {      }{      }  {      }{      }  {      }{      }
 (                )(                )(                )
{                                                      }

If the brackets are not balanced (that is, a matching bracket appears when some of the brackets in the middle have not been closed), the program should print 'Invalid input!'.

For example, give this input:


Your program should output:

Invalid input!


A new version of the popular board game Scrabble is coming out soon, and they want you to write a program to calculate the score for a word on the board.

In this new version of Scrabble, instead of the score for a word placement being the sum of the values of each individual letter, the score for the word is the number of distinct "subwords" it contains. The definition of a subword is recursive: a subword is constructed by removing a single letter from the word, and the subword has to be a valid dictionary word.

For example, the five subwords for the word lion are lion, ion, in, on and i (in our dictionary). Note that even though lo is made up of the letters of lion and is a valid dictionary word, it is not counted because there is no path of subwords from lion to lo.

So for the sample input:


your program should output:


For this input:


your program should output:


Your program will read the contents of the dictionary of words from a file words.txt, with each line containing a single dictionary word. You can download the word file here.

I have some idea, but really need pointers on how to do these (or just straight answers). please help?

Interesting problems, but you got to show us some code of your own attempts at this!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.