0

input関数を使おうとしたら以下のようなエラーになってしまいました。

File "<ipython-input-21-dfdd02906783>", line 39
    answer_num = input("解答:")
             ^
SyntaxError: invalid syntax

どのようにしたら解決できますか?

# -*- coding: utf-8 -*-
import re
import random
import numpy as np
source = 'english_words.txt'

with oprn(source,'r',encoding = 'utf-8') as f:
    data = f.read().splitlines() 
    english_words = [l.strip() for i, l in enumerate(data) if ((i%2) == 0)] 
    jp_meanings = [l.strip() for i, l in enumerate(data) if ((i%2) != 0)]   

words_dict = dict(zip(english_words,jp_meanings))   


n_questions = 50   



random_index = np.random.randint(low = 0, high = len(english_words), size = n_questions) 
for question_num in range(n_questions):  
    question_word = english_words[random_index[question_num]] 
    correct_answer = words_dict[question_word]    
    meanings_copy =jp_meanings.copy()         
    meanings_copy.remove(correct_answer)
    wrong_answers = random.sample(meanings_copy,3)   

    answer_options = [correct_answer] + wrong_answers    

    random.shuffle(answer_options)    
    correct_index = answer_options.index(correct_answer)

    print('問{}. {}\n\n'.format(question_num + 1,question_word))  
    for i in range(4):
        print('{}.{}\n'.format(i + 1, answer_options[i])   
    answer_num = input("解答:") # ←←←←←←←←←←←←←←←←←←←←←ここです
    answer_num = int(answer_num)
    if answer_num = correct_index + 1:
        print('correct!')
    else:
        print('wrong!')
        print('correct answer is '+'correct_answer')
    print('\n\n')

1 件の回答 1

1
   print('{}.{}\n'.format(i + 1, answer_options[i])   

カッコの数があってません

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。