Create a two-dimensional array at runtime: Difference between revisions

→‎{{header|Python}}: Python 2 is reaching end of life. Adjusting code so that it works in Python 3
(Regrouped BASIC examples, added Commodore BASIC example)
(→‎{{header|Python}}: Python 2 is reaching end of life. Adjusting code so that it works in Python 3)
Line 1,899:
 
=={{header|Python}}==
{{works with|Python| 2.5 and 3.6}}
 
<lang python>width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in xrangerange(height)]
myarray[0][0] = 3.5
print (myarray[0][0])</lang>
 
'''Note:''' Some people may instinctively try to write myarray as [[0] * width] * height, but the * operator creates ''n'' references to [[0] * width]
Line 1,914:
# or, in pre 2.7 versions of Python: myarray = dict(((w,h), 0) for w in range(width) for h in range(height))
myarray[(0,0)] = 3.5
print (myarray[(0,0)])</lang>
 
=={{header|R}}==
Anonymous user