Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework-excercise
#3
f=[]

for i in range (5):
    line = []
    for j in range (5):
        line.append(random.randint(1,10))
    f.append(line)

for each in f:
    print(each)
    print (sum(each))
Output:
[10, 7, 6, 2, 9] 34 [3, 8, 4, 7, 1] 23 [1, 2, 10, 5, 1] 19 [3, 3, 2, 9, 10] 27 [10, 1, 5, 4, 1][10, 7, 6, 2, 9] 34 [3, 8, 4, 7, 1] 23 [1, 2, 10, 5, 1] 19 [3, 3, 2, 9, 10] 27 [10, 1, 5, 4, 1] 21 21
It works. Maybe you made a mistake with indentation.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
Homework-excercise - by gmit01 - Dec-10-2017, 08:13 PM
RE: Homework-excercise - by j.crater - Dec-10-2017, 08:18 PM
RE: Homework-excercise - by DeaD_EyE - Dec-11-2017, 08:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with the excercise alani 3 2,154 Apr-19-2020, 07:29 PM
Last Post: deanhystad
  Program excercise SushiRolz 1 2,480 Feb-28-2018, 01:48 AM
Last Post: Larz60+
  excercise python list Kykoss 7 4,018 Feb-11-2018, 03:08 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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