Python Forum
Need to find a mistake in my code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need to find a mistake in my code
#1
A=Matrix([[1,2,0],[4,5,0],[7,8,9]]);A
def Kostenmatrix(A):
    C=Matrix(A.nrows(),[])
    for i in range(0.A.nrows()):
        for j in range(0,A.nrows()):
            if i==j:
                C[i,j]=0
            elif A[i,j]==0 and i<>j:
                C[i,j]=10^4
            else:
                C[i,j]=A[i,j]

    return C
Kostenmatrix(A)
︡1d7ac8e1-aea5-4323-8e3c-45ee125883e2︡{"stdout":"[1 2 0]\n[4 5 0]\n[7 8 9]\n"}︡{"stderr":"Error in lines 13-13\nTraceback (most recent call last):\n  File \"/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py\", line 1013, in execute\n    exec compile(block+'\\n', '', 'single') in namespace, locals\n  File \"\", line 1, in <module>\n  File \"\", line 3, in Kostenmatrix\n  File \"sage/structure/element.pyx\", line 484, in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4377)\n    return self.getattr_from_category(name)\n  File \"sage/structure/element.pyx\", line 497, in sage.structure.element.Element.getattr_from_category (build/cythonized/sage/structure/element.c:4486)\n    return getattr_from_other_class(self, cls, name)\n  File \"sage/cpython/getattr.pyx\", line 254, in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:1901)\n    raise dummy_attribute_error\nAttributeError: 'sage.rings.integer.Integer' object has no attribute 'A'\n"}︡{"done":true}︡
Iam using " sage" which is pretty similar to python. I just hope that someone can help me becasue i simply cannot understand why my function Kostenmatrix(A) is putting out an error.
Reply
#2
I've never used sage before, but take a look at this link:

https://ask.sagemath.org/question/8131/a...ibute-mod/

seems sage doesn't work properly (sometimes) with range, due the Sage Integer type.

It's just a guess, as I've never used sage before.
Reply
#3
At line 4, there is a dot . between 0 and A. It should be a comma ,.
Reply
#4
thanks, now everything works.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 1,054 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  [Solved] Please, help me find a simple mistake AlekseyPython 2 1,751 Jun-17-2021, 12:20 PM
Last Post: AlekseyPython
  [split] Could you please clarify where i did mistake also how run without admin right Abubakkar 1 1,797 Jun-14-2021, 09:32 AM
Last Post: Larz60+
  Please help to me to find my mistake in code leonardin 2 1,848 Nov-29-2020, 04:17 PM
Last Post: Larz60+
  minor mistake in code for factorial spalisetty06 2 1,886 Aug-22-2020, 05:00 PM
Last Post: spalisetty06
  Simple mistake about for Nomatter 4 2,261 Jul-16-2020, 02:24 PM
Last Post: Nomatter
  Find the realpath for a symlinked .pth file in itself with python code. hongyi 7 3,080 Apr-27-2020, 05:30 AM
Last Post: Larz60+
  Install Mistake jlerette5 1 1,898 Feb-18-2020, 12:19 AM
Last Post: jefsummers
  What was my mistake in this Python code (easy)? voltman 4 3,458 Nov-19-2019, 09:58 PM
Last Post: snippsat
  countdown script not working..plz help what is mistake randyjack 1 2,116 Oct-28-2019, 06:57 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020