My Python Script:
app = "google facebook yahoo"
prec = 0
test = 0
while test < 4 :
print "The test is test%d" % (test)
while prec < 4 :
prec = prec + 1
for i in app.split():
print "The word is " + (i) + " precedence %d" % (prec)
Actual Output now:
Its printing continuously the following
The test is test0
The test is test0
The test is test0
The test is test0
The test is test0
The test is test0
Expected Output:
The test1 is
The word is google precedence 1
The word is facebook precedence 2
The word is yahoo precedence 3
The test2 is
The word is google precedence 1
The word is facebook precedence 2
The word is yahoo precedence 3
The test3 is
The word is google precedence 1
The word is facebook precedence 2
The word is yahoo precedence 3
The test4 is
The word is google precedence 1
The word is facebook precedence 2
The word is yahoo precedence 3
Please guide me on how to achieve this output. Thanks in advance.
One problem is that your loops are not nested. The next thing is that your first loop
is an infinite loop, because your variable "test" is set to 0 and that never changes in the loop. So test<4 is always true.
You could do something like that.