Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework-excercise
#1
Hi,
I'm a student to 1st semester and I have a problem to solve:
"Create a 5x5 random number table and calculate the sum of items per line, per column, and the sum of the elements in the diagonal table. Save the results to a text file."
This is my code until to the sum of items per line. After that I'm stuck!

import random

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))
If anyone knows please reply.
Thanks in advance,
gmit
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,258 Apr-19-2020, 07:29 PM
Last Post: deanhystad
  Program excercise SushiRolz 1 2,599 Feb-28-2018, 01:48 AM
Last Post: Larz60+
  excercise python list Kykoss 7 4,214 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