You might want to check out the '2to3' program to convert Python 2.x
code to Python 3.x code.
The following command worked to change your code to runnable Python 3.x
code:
2to3 -w <your file containing 2.x code>
--
Steve Mayer
smaye...@me.com
On 8 Jan 2014, at 10:19, S Tareq wrote:
need help how to run it on python 3.3, or change it to python 3.3 when
i run it says syntax error if i run it on python 2.7 it works.
# Import statements
import random
import datetime
#Arrays to store the definitions and keywords read from the file
keywords=[];
definition=[];
correctAnswer=[];
#Counter for the wrong Answer and counter of number of definition in
correctAnswerCounter=0
wrongAnswer=0;
counter=0;
# Taking User input for accepting the file name to be read
filename= raw_input("Enter the File Name with extension")
#Reading the file from start to the end
for line in open(filename,'r').readlines():
if(counter%2==0):
keywords.append(line);
counter=counter+1;
correctAnswer.append(0)
else:
definition.append(line);
keys=[];
keys=line.split(" ");
counter=counter+1;
# Running two while loops to make the pattern recursive
while True:
# Starting the time for quiz and also, creating variables to make sure
that same sequences and answers are not repeated
a = datetime.datetime.now().replace(microsecond=0)
prevWord=0
prevSeq=0
# While loop to run the code till each answer is correctly
answered
while correctAnswer.count(2)!=(counter/2):
#While loop to generate an different random number from
one the generated previously
while True:
word=random.randint(0,(counter/2)-1)
if(correctAnswer[word]!=2):
break;
if(prevWord==word):
continue;
# Displaying the new keyword each time.
print "Please Select the number which is the correct
definition of the word:" ,keywords[word]
#Generating an new sequence each time different from
previous one
while True:
sequences =random.randint(0,2)
if(prevSeq==sequences):
continue;
else:
break
#Generating an new incorrect answer each time different
from previous one
while True:
incorrectAnswer=random.randint(0,len(correctAnswer)-1)
if(incorrectAnswer==word):
continue;
else :
break
#Generating an new incorrect answer each time different
from previous one
while True:
incorrectAnswerSecond=random.randint(0,len(correctAnswer)-1);
if (incorrectAnswer==incorrectAnswerSecond):
continue
if(incorrectAnswerSecond==word):
continue
else:
break
# Displaying the options to the user based on the sequence
number generated
if (sequences==0):
print "1.",definition[word]
print "2.",definition[incorrectAnswer]
print "3.",definition[incorrectAnswerSecond]
elif (sequences==1):
print "1.",definition[incorrectAnswer]
print "2.",definition[incorrectAnswerSecond]
print "3.",definition[word]
elif (sequences==2):
print "1.",definition[incorrectAnswerSecond]
print "2.",definition[word]
print "3.",definition[incorrectAnswer]
#Taking the answer from user
answer = raw_input("Enter the Correct Number between 1 to
3")
# Assign the seq and word to preseq and word
prevSeq=sequences
prevWord=word
#Checking the answer if they are corret.
if(0 == sequences):
if(answer == "1"):
print "success"
correctAnswer[word]=correctAnswer[word]+1
correctAnswerCounter=correctAnswerCounter+1
else:
print "Wrong Answer"
print "Correct Answer: " ,definition[word]
wrongAnswer=wrongAnswer+1;
elif(1 == sequences):
if(answer == "3"):
print "success"
correctAnswer[word]=correctAnswer[word]+1
correctAnswerCounter=correctAnswerCounter+1
else:
print "Wrong Answer"
print "Correct Answer: " ,definition[word]
wrongAnswer=wrongAnswer+1;
elif(2 == sequences):
if(answer == "2"):
print "success"
correctAnswer[word]=correctAnswer[word]+1
correctAnswerCounter=correctAnswerCounter+1
else:
print "Wrong Answer"
print "Correct Answer: " ,definition[word]
wrongAnswer=wrongAnswer+1
# Stopping the time of the clock
b = datetime.datetime.now().replace(microsecond=0)
# displaying number of wrong answer and total quiz time
print "Total Number of Wrong Answer:", wrongAnswer
print "Total Quiz Time", (b-a)
print "Total Number of correct Answer", correctAnswerCounter
#asking user to reenter
restart= raw_input("Do You want to start the quiz again Yes or
No")
if(restart=="no"):
print "Thanks for quiz"
break;
elif(restart=="yes"):
wrongAnswer=0
correctAnswerCounter=0;
correctAnswer=[];
i=0
while (i<(counter/2)):
i=i+1
correctAnswer.append(0)_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor