2017-04-09 63 views
0

这只是我的第4个Python程序。我正在与elif和/或其他语句挣扎。我在代码中放置注释来解释我的目标是随机使用一个数组(1到12)不重复,检查正确和错误的答案,保持得分,跟踪尝试并打印出总分数。我做了一个导入numpy作为np和随机随机Python(While和Elif语句) - 检查数学错误

print ('''      Super Multiplication Master! 
    This is a multiplication flashcard game in which you will be asked to 
    multiply math facts. Be sure to study your times tables 1 to 12. Your 
    attempts and score will be tallied. Try your best! You got this Math 
    Master! If you need a break, press 'q' to quit\n''' ) 

    input('Ready, set go! Press enter to continue') 

    array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] 
    attempts = 0 
    score = 0 

    def multiplication_game(array): 
     c= random.array 
     b= random.array 
     a = b*c 
     d = int(input('What is '+b+ ' x ' +c+ '?: ')) 

    while a==d: 
     score = (score+5) 
     attempts = (attempts+1) 
    elif a != d: 
     print('sorry, the correct answer is ' + a) 
     score = (score-5) 
     attempts= (attempts +1) 

q = input() 
for q: 
if score >= 35: 
    print('You did great, you got '+score+ 'out of 40') 
if score ==30 or score ==25: 
    print('You are doing well you got' +score+ 'out of 40') 
if score == 20: 
    print ('Okay, you got' +score+ 'out of 40. You are halfway to being a master') 
if score <= 15: 
    print('Okay, you got' +score+ 'out of 40. A little more practice and you will become a master') 
else break' 

任何帮助将不胜感激,我从书中学习,如果这有助于理解上下文。我正试图围住它。

+2

某处有问题,你的缩进......请确保代码的正确性和运行,并包含所有进口了。谢谢! :-) – darthbith

+0

您的缩进是一团糟,如上所述,也是您的最后一行包含语法错误 –

回答

1

你应该看看你的终端有关你编译文件时出现了什么错误。它应该告诉你文件中的缩进问题。您可以使用制表符或四个空格作为缩进,并使其一致。

+0

好的,谢谢你会这样做! – abi

0

尝试导入随机库


import random