Aug-21-2017, 10:03 AM
I am just a beginner. I am slowly working my way through 'How to Automate the Boring Stuff' by Al Sweigart
In the code below, I can't see what the %s is, or %
The code works ok, to my amazement, I'd just like to know why in quizFile = open('capitalsquiz%s.txt' % (quizNum + 1), 'w') quizNum is %s from the loop in the text part, because it correctly creates capitalsquiz1.txt and so on. How does this work? Why write %s? What is %? I understand (quizNum + 1), because range begins at 0.
As far as I know, python has % as modulo like 22 % 8 = 6
In the code below, I can't see what the %s is, or %
The code works ok, to my amazement, I'd just like to know why in quizFile = open('capitalsquiz%s.txt' % (quizNum + 1), 'w') quizNum is %s from the loop in the text part, because it correctly creates capitalsquiz1.txt and so on. How does this work? Why write %s? What is %? I understand (quizNum + 1), because range begins at 0.
As far as I know, python has % as modulo like 22 % 8 = 6
# Generate 35 quiz files. for quizNum in range(35): # Create the quiz and answer key files. quizFile = open('capitalsquiz%s.txt' % (quizNum + 1), 'w') answerKeyFile = open('capitalsquiz_answers%s.txt' % (quizNum + 1), 'w')