“第357行:语法错误,意外的kEND,期待$ end”

时间:2013-06-02 01:20:20

标签: ruby

这是我的代码。能帮我理解错误吗? “第357行:语法错误,意外的kEND,期待$ end”

我是Ruby新手。阅读许多教程并开发此代码。

$guess=0 
$j=0 
$ans = ""


def questions(no)

 case no

  when 1
    puts "\nWhat is 1+1 ? "
    puts "\n\na) 2 \tb) 3\t c) 4\n"
    puts "\nInput your answer a or b or c: "
    ans = gets.chomp


    if ans.casecmp("A") == 0

       puts "\n\t\tWrong :o :o :o"   
       guess=guess+1 
       return 1


    else

       puts "\n\t\tCorrect!!!"       
       return 0

    end   



  when 2
    puts "\nWhat is a OS ? "
    puts "\n\na) XP\tb) PX\t c) UI\n"
    puts "\nInput your answer a or b or c: "
    ans = gets.chomp

    if ans.casecmp("A") == 0

       puts "\n\t\tWrong :o :o :o"   
       guess=guess+1 
       return 1


    else

       puts "\n\t\tCorrect!!!"       
       return 0

    end   

  when 3
    puts "\nWhat is 1+2 ? "
    puts "\n\na) 2 \tb) 3\t c) 4\n"
    puts "\nInput your answer a or b or c: "
     ans = gets.chomp

    if ans.casecmp("B") == 0

       puts "\n\t\tWrong :o :o :o"   
       guess=guess+1 
       return 1


    else

       puts "\n\t\tCorrect!!!"       
       return 0

    end   

   when 4
    puts "\nWhat is 1+3 ? "
    puts "\n\na) 2 \tb) 3\t c) 4\n"
    puts "\nInput your answer a or b or c: "
     ans = gets.chomp

    if ans.casecmp("C") == 0

       puts "\n\t\tWrong :o :o :o"   
       guess=guess+1 
       return 1


    else

       puts "\n\t\tCorrect!!!"       
       return 0

    end   

   when 5
    puts "\nWhat is 1+4 ? "
    puts "\n\na) 5 \tb) 3\t c) 4\n"
    puts "\nInput your answer a or b or c: "
     ans = gets.chomp

    if ans.casecmp("A") == 0

       puts "\n\t\tWrong :o :o :o"   
       guess=guess+1 
       return 1


    else

       puts "\n\t\tCorrect!!!"       
       return 0

    end   

  when 6
    puts "\nWhat is 1+5 ? "
    puts "\n\na) 2 \tb) 3\t c) 6\n"
    puts "\nInput your answer a or b or c: "
     ans = gets.chomp

    if ans.casecmp("C") == 0

       puts "\n\t\tWrong :o :o :o"   
       guess=guess+1 
       return 1


    else

       puts "\n\t\tCorrect!!!"       
       return 0

    end   

  when 7
    puts "\nWhat is 1+6 ? "
    puts "\n\na) 2 \tb) 7\t c) 4\n"
    puts "\nInput your answer a or b or c: "
     ans = gets.chomp

    if ans.casecmp("B") == 0

       puts "\n\t\tWrong :o :o :o"   
       guess=guess+1 
       return 1


    else

       puts "\n\t\tCorrect!!!"       
       return 0

    end   

  when 8
    puts "\nWhat is 1+7 ? "
    puts "\n\na) 2 \tb) 8\t c) 4\n"
    puts "\nInput your answer a or b or c: "
     ans = gets.chomp

    if ans.casecmp("B") == 0

       puts "\n\t\tWrong :o :o :o"   
       guess=guess+1 
       return 1


    else

       puts "\n\t\tCorrect!!!"       
       return 0

    end   

  when 9
    puts "\nWhat is 1+8 ? "
    puts "\n\na) 9 \tb) 3\t c) 4\n"
    puts "\nInput your answer a or b or c: "
     ans = gets.chomp

    if ans.casecmp("A") == 0

       puts "\n\t\tWrong :o :o :o"   
       guess=guess+1 
       return 1


    else

       puts "\n\t\tCorrect!!!"       
       return 0

    end   

  when 10
    puts "\nWhat is 1+9 ? "
    puts "\n\na) 10 \tb) 3\t c) 4\n"
    puts "\nInput your answer a or b or c: "
     ans = gets.chomp

    if ans.casecmp("A") == 0

       puts "\n\t\tWrong :o :o :o"   
       guess=guess+1 
       return 1


    else

       puts "\n\t\tCorrect!!!"       
       return 0

    end  

  end

end




def check()

    case guess

        when 1

             puts "\n\n\n\n\n\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t       _|_"

        when 2
             puts "\n\n\n\n\n\n\t\t\t\t__________"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t\t|"
             puts "\n\t\t\t       _|_"


        when 3
             puts "\n\n\n\n\n\n\t\t\t\t__________" 
             puts "\n\t\t\t\t|        |" 
             puts "\n\t\t\t\t|        O" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t       _|_" 

        when 4
             puts "\n\n\n\n\n\n\t\t\t\t__________" 
             puts "\n\t\t\t\t|        |" 
             puts "\n\t\t\t\t|        O" 
             puts "\n\t\t\t\t|       \\|/" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t       _|_" 

        when 5
             puts "\n\n\n\n\n\n\t\t\t\t__________" 
             puts "\n\t\t\t\t|        |" 
             puts "\n\t\t\t\t|        O" 
             puts "\n\t\t\t\t|       \\|/" 
             puts "\n\t\t\t\t|        |" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t       _|_" 

        when 6
             puts "\n\n\n\n\n\n\t\t\t\t__________" 
             puts "\n\t\t\t\t|        |" 
             puts "\n\t\t\t\t|        O" 
             puts "\n\t\t\t\t|       \\|/" 
             puts "\n\t\t\t\t|        |" 
             puts "\n\t\t\t\t|       / \\" 
             puts "\n\t\t\t\t|     --------" 
             puts "\n\t\t\t\t|       |  |" 
             puts "\n\t\t\t\t|       |  |" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t       _|_" 
             puts "\n\n\t\t\t\t\tOne Chance Left-> :) " 

        when 7
             puts "\n\n\n\n\n\n\n\t\t\t\t!!!The Man is Hanged!!!" 
             puts "\n\n\n\n\n\t\t\t\t__________" 
             puts "\n\t\t\t\t|        |" 
             puts "\n\t\t\t\t|        0" 
             puts "\n\t\t\t\t|       \\|/" 
             puts "\n\t\t\t\t|        |" 
             puts "\n\t\t\t\t|       / \\" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t\t|" 
             puts "\n\t\t\t       _|_" 
             puts "\n\n\t\t\t\t\t\t\t Man Died :o :o :o" 
             puts "\n\n\n\t\t\t\t    !!!Game Over!!!" 

        else
             puts "\n\t\t\t\tProceed Press Enter->" 

    end
end



    puts "\n\n\n\n\n\n\n\n\n" 
    puts "\n\t\t\t\t-------------------------" 
    puts "\n\t\t\t\t|                       |" 
    puts "\n\t\t\t\t|  !!!HangMan Game!!!   |" 
    puts "\n\t\t\t\t|                       |" 
    puts "\n\t\t\t\t-------------------------" 
    puts "\n\n\nRules: " 
    puts "\n------" 
    puts "\n\n1. You have 10 Questions." 
    puts "\n\n2. You have 7 Chances." 
    puts "\n\n3. For every Wrong Answer Man will be stepped towards hanging :O :O :O " 
    puts "\n\n4. Answer all the 10 questions before the man hangs!!!" 
    puts "\n\n\n\n\n\n\t\t\t\t    !!!Best of Luck!!!" 
    puts "\n\n\n\t\t\t\t\t      Game designed by DHANABHARATHI,PEC"     

    for i in 1..10 do          

        k=0       
                j=10-i 
        puts "\n\n\t\t\t\t\t\t\t\t#{j} Questions More" 
        k = questions(i) 

        if k==1 
            check 
        end

        break if guess>=7       
        i=i+1
                end


    end //LINE 357

    if guess<7
    puts "\n\t\t\t\t     You Won!!! Congrats!!!" 
    puts "\n\t\t\t\t     ________   ______________" 

    else
    puts "\n\n\n\t\t\t\t       You lose!!!" 
    end

请教我如何清除错误并使我的代码正常工作

1 个答案:

答案 0 :(得分:1)

你在第354行结束了我认为不应该在那里,改变这一点:

    break if guess>=7       
    i=i+1
    end


end

到此:

    break if guess>=7       
    i=i+1


end