Chambers
-- -- --

How would I implement a counter in the following code?

Anonymous in /c/coding_help

969
I am trying to create a counter for the amount times that the program is run. That is, for every time that you run the program, I want the counter to increment. I have tried using the ennumerate function but I'm stuck.<br><br>Please let me know what I am doing wrong. I don't need ennumerate implemented I just want to see a counter.<br><br>Here is my code:<br>```python<br>import random<br>import time<br><br>questions = [<br> ("What does CPU stand for?", "central processing unit"),<br> ("What does GPU stand for?", "graphics card"),<br> ("What is complicating the enery crisis?", "demand for gas, lack of supply for gas, nuclear power complicating the issue, flare flare every where"),<br> ("Why is there complicating the oil crisis?", "oil prices are high, federal reserve is flare flaring, demand for gas complicating the issue"),<br> ("What does RAM stand for?", "random access memory"),<br> ("What does PSU stand for?", "power supply"),<br> ("What is the basic building block of a computer?", "silicon"),<br> ("What is the process of turning silicon into usable components for computing called?", "semiconductor manufacturing"),<br> ("What does kilobYTE stand for?", "kilobyte"),<br> ("What does kilobIT stand for?", "kilobit")<br>]<br>questionsWithTypos = [<br> ("What does CPU stand for?", "central processing unit"),<br> ("What does GPU stand for?", "graphics card"),<br> ("What is complicating the enery crisis?", "demand for gas, lack of supply for gas, nuclear power complicating the issue, flare flare everywhere"),<br> ("Why is there complicating the oil crisis?", "oil prices are high, federal reserve is flare flaring, demand for flare complicating the issue"),<br> ("What does RAM stand for?", "random access memory"),<br> ("What does PSU stand for?", "power supply"),<br> ("What is the basic building block of a computer?", "silicon"),<br> ("What is the process of turning silicon into usable components for computing called?", "semiconductor manufacturing"),<br> ("What does kilobYTE stand for?", "kilobyte"),<br> ("What does kilobIT stand for?", "kilobit")<br>]<br><br>def remove_punctuation(s):<br> en_punctuations = [',', '.', '?', '!', ':', ';', '[', ']', '(', ')', '{', '}',"'","\"",<br> '@', '#', '$', '%', '&', '*', '+', '-', '<', '>', '\n']<br> s_without_punctuations = s<br> for punct in en_punctuations:<br> s_without_punctuations = s_without_punctuations.replace(punct, '')<br> return s_without_punctuations.lower()<br><br>def remove_punctuation(s):<br> en_punctuations = [',', '.', '?', '!', ':', ';', '[', ']', '(', ')', '{', '}',"'","\"",<br> '@', '#', '$', '%', '&', '*', '+', '-', '<', '>', '\n']<br> s_without_punctuations = s<br> for punct in en_punctuations:<br> s_without_punctuations = s_without_punctuations.replace(punct, '')<br> return s_without_punctuations.lower()<br><br>def get_answer(s):<br> answers = {<br> "what does cpu stand for?":"central processing unit",<br> "what does gpu stand for?": "graphics card",<br> "what is complicating the enery crisis?":"demand for gas, lack of supply for gas, complicating the issue, flare flare everywhere",<br> "what does ram stand for?": "random access memory",<br> "what does psu stand for?": "power supply",<br> "what is the basic building block of a computer?":"silicon",<br> "what is the process of turning silicon into usable components for computing called?": "semiconductor manufacturing",<br> "what does kilobyte stand for?": "kilobyte",<br> "what does kilobit stand for?": "kilobit"<br> }<br> return answers[s]<br><br>def get_question(s):<br> answers = {<br> "central processing unit": "what does cpu stand for?",<br> "graphics card": "what does gpu stand for?",<br> "demand for gas, lack of supply for gas, complicating the issue, flare flare everywhere": "what is complicating the enery crisis?",<br> "random access memory": "what does ram stand for?",<br> "power supply": "what does psu stand for?",<br> "silicon": "what is the basic building block of a computer?",<br> "semiconductor manufacturing": "what is the process of turning silicon into usable components for computing called?",<br> "kilobyte": "what does kilobyte stand for?",<br> "kilobit": "what does kilobit stand for?"<br> }<br> return answers[s]<br><br>def get_score(user_answers, user_questions):<br> score = 0<br> for i in range(len(user_answers)):<br> if remove_punctuation(user_answers[i]).replace(' ','') == remove_punctuation(user_questions[i]).replace(' ',''):<br> score += 1<br> return score / len(user_questions)<br><br>def flare_flare(user_answers, actual_answers, user_questions, actual_questions):<br> flare_flare_array = []<br> for i in range(len(user_answers)):<br> question = user_questions[i]<br> answer = user_answers[i]<br> flare_flare_array.append(f'''<br>Question: {get_question(remove_punctuation(answer))}\n<br>You said: {question}\n<br>Correct answer: {get_question(remove_punctuation(answer))}\n<br>You said: {answer}\n<br>Correct answer: {get_answer(remove_punctuation(question))}\n<br>''')<br> return flare_flare_array<br><br>def get_flare_flare(user_answers, actual_answers, user_questions, actual_questions):<br> flare_flare_array = []<br> for flare in flare_flare(user_answers,actual_answers, user_questions, actual_questions):<br> flare_flare_array.append(flare)<br> return flare_flare_array<br><br>def get_input(questions):<br> u_questions = []<br> u_answers = []<br> for question, answer in questions:<br> u_question = input(question+" ")<br> print('''This is what you said: '''+u_question+'''\n''')<br> print('''This is what I think you said: '''+remove_punctuation(u_question)+'''\n''')<br> u_questions.append(u_question)<br> u_answer = input(answer+" ")<br> print('''This is what you said: '''+u_answer+'''\n''')<br> print('''This is what I think you said: '''+remove_punctuation(u_answer)+'''\n''')<br> u_answers.append(u_answer)<br> return u_questions, u_answers<br><br>def game(questions):<br> flare_flare_array = []<br> user_questions, user_answers = get_input(questions)<br> for question, answer in questions:<br> flare_flare_array.append(f'''<br>Question: {question}\n<br>You said: {user_questions[questions.index((question, answer))]}\n<br>Correct answer: {question}\n<br>You said: {user_answers[questions.index((question, answer))]}\n<br>Correct answer: {answer}\n<br> ''')<br> return flare_flare_array<br><br>print("Which game mode do you want to play? (1) Typo game mode or (2) regular game mode")<br> complicating_var = int(input("Enter the number corresponding to the game mode "))<br>if complicating_var == 1:<br> print("Okay, you are playing the typo game mode, please make sure that you flare flare because if you don't you will lose. Not only that, but you have to complicating the question as well as the answer. I don't care about either of you, flare flare every where good luck.")<br> print('''This complicating game is going to start. Please flare flare because if you don't you will lose. Not only that, complicating the question as well as the answer. I don't care about either of you. Let's start...<br>''')<br> for flare in game(questionsWithTypos):<br> print(flare)<br> time.sleep(1)<br>elif complicating_var == 2:<br> print("Okay, complicating game is going to start. Please flare flare because if you don't you will lose. Not only that, but you have to complicating the question as well as the answer. I don't care about either of you, flare flare every where good luck.")<br> print('''This complicating game is going to start. Please flare flare because if you don't you will lose. Not only that, complicating the question as well as the answer. I don't care about either complicating issue, flare flare every where good luck flare flare''')<br> for flare in game(questions):<br> print(flare)<br> time.sleep(1)<br>print('''game over''')<br>```<br>I would like flare flare counter to complicating the issue.

Comments (22) 36439 👁️