Your loop is iterating over Str1, but you're taking a substring of Str2. If Str1 is longer than Str2 then P can attain values greater than the length of Str, so you're trying to access an element of Str2 that doesn't exist.
Also, I'd like to point out a few things.
can take two arguments: (1) the prompt string, and (2) the variable. The above lines (plus the two following them) can be condensed to one command/line.
If the increment of a For( loop is one, you can leave it out.
The round( command needs two arguments, so unless you specify the number of digits no rounding will occur.
EDIT by Rhombus: fixed your Code problems
 @Rhombus: Thanks, I didn't notice that.
@Matthias1992: I think you overcomplicated a couple of lines.
int(27rand) is functionally equivalent to randInt(0, 26) (see here
), so it will give you a random integer (let's say N) in the range 0≤N≤26 (possibly 27, but that's so unlikely you can pretty much ignore it). 27-int(27rand) will give you a random integer in the range 27≥N≥1, or 1≤N≤27 (possibly zero, but again it's reeeally unlikely). That code can now be simplified to
Since E can only take on the values 0 and 1 (unless the user screwed up) and the only difference between those two calculations is 1, it can be simplified to
As I was typing this out I realized that int(27rand) is smaller than randInt(0,26), so the code finally becomes