Python Forum
need help with tutorial question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help with tutorial question
#1
Discuss how lists containing lists can be used to represent tables in Python. Write a program in Python that asks user to input 5 lines of numbers. Your program should represent these lines as a table. 

NOTE: Think carefully about which lists will have a fixed size and which lists will have a variable size. 

For example: Enter some numbers: 1 2 3 4 5 
Enter some numbers: 5 6 7 
Enter some numbers: 1 1 1 1
Enter some numbers: 1.5 6 7.5 2 
Enter some numbers: 0 

[[1, 2, 3, 4, 5], [5, 6, 7], [1, 1, 1, 1], [1.5, 6, 7.5, 2], [0]] 

NOTE: As the input function returns a string, you will be required to split the string.

Once you have some experience with tables as lists of lists, consider the following line of code:
new_table = [[1,2,3]] * 5

Using the techniques you have learnt so far, work out what this code does. As a pair discuss what you think will happen when you change the first element of the first list to 0. 
new_table[0][0] = 0

What happened? Did the table behave as expected? If not, what possible explanation could there be for the behaviour of the table? Discuss your findings with your demonstrator. 

** Currently stuck with this question, this doesn't carry any assignment marks in my semester so i'm just requesting for help here, currently i'm only able to print numbers which can result exactly like this [[1, 2, 3, 4, 5], [5, 6, 7], [1, 1, 1, 1], [1.5, 6, 7.5, 2], [0]] , but the problem with mine is that mine has the double quotes which means it's a string, but i can't think of a way to convert it to integers .. need help :)
Reply
#2
What have you tried? While the good people on this forum are willing to help by answering specific questions, more or less no one is willing to do your [home]work for you.
Show us your code and ask specific questions.
Reply
#3
You literally didn't ask for help with anything, that's just your homework copy-pasted. If that's the extent of the effort you want to put into it, then I expect payment for services rendered :)

USD $100.
USD $350 for a rush job (before midnight tonight).
Reply
#4
list = ['1', '2', '3']
new_list = [int(text) for text in list]
Note that the above is only going to get you part way there. It's going to fail on the fourth line of sample input.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
sorry i just forgot to paste my code but i specified my question at the bottom of my post
n = 0
List = [0]*5
while n < 5 :
List[n] = input("Enter some numbers here").split()
n = n + 1

These code gave me a table of strings and i was asking for a way to convert them to integer, but it's ok i figured it out by doing a nested loop
for i in range(len(List)):
for j in range(len(List[i])):
List[i][j] = int(List[i][j])

so it's all cool sorry for this :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Tutorial range function question HawkeyeKnight 2 2,691 Sep-27-2018, 09:45 AM
Last Post: ThiefOfTime

Forum Jump:

User Panel Messages

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