Ask Your Question
0

Code error in sagemath

asked 2017-02-12 03:08:47 +0100

davis gravatar image

My code in sagemath

    def bruteforce
    count = 0
     s = [0, 1, 2, 4, 8]
   s.each do |a|
s.each do |b|
  s.each do |c|
    s.each do |d|
      s.each do |e|
        if a+b+c+d+e == 8
          count += 1
          puts "#{count}.: #{a}+#{b}+#{c}+#{d}+#{e}"
          end
        end
      end
     end
    end
   end
  count
  end

but it was an error as below

  File "<ipython-input-1-87370adfacc9>", line 1
       def brutefor 
    SyntaxError: invalid syntax
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-02-13 13:38:32 +0100

Clemens Heuberger gravatar image

SageMath code is written in Python (with a few extensions by the preparser). Your code does not resemble Python. Indentation matters, no end is required, forloops are written as for b in s:, functions are defined as def bruteforce():, write print instead of puts.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-02-12 03:08:47 +0100

Seen: 360 times

Last updated: Feb 13 '17