Skip to content

A More Novice Solution to Question 7 #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

A More Novice Solution to Question 7 #141

wants to merge 3 commits into from

Conversation

acidsafari
Copy link

As I am going through the exercises, I've been trying to solve some of the problems with the basic skills I have.
For Q-7 I have managed to find a solution using more basic code.
Hope it is of help to those learning.
'''
values = input('Please Enter Numbers separated by Comma: ')

l = list() #array list
sl = list() #sub list
i = 0 # i-dimensional counter
j = 0 # j-dimensional counter
d = (values.split(',')) # creating an input list
X = int(d[0])
Y = int(d[1])
while i < X : # creating X-1 arrays
while j < Y : # creating the Y-1 array
y = i * j
j = j + 1
sl.append(y) # creating the Y arrays
j = 0 # to reset the counter back to 0 on each iteration
#print(sl) # print check
i = i + 1
l.append(sl)
sl = list() # RESETING Y array LIST BACK TO 0

print(l)
'''

solving these problems helps a lot developing the understanding of python, thanks for putting together this list
As I continue to progress through the exercises, you might find some more novice solution to the questions given.
@Sam-Gunawan
Copy link

I think it's also too complicated if you solve it that way (in my opinion). There's just too much assignment operators and there are some unnecessary variables. For a more Pythonic way while maintaining a beginner's mindset, I'd go for this:

x, y = input().split(",")
result = []
nest_arr = []
for i in range(int(x)):
    for j in range(int(y)):
        nest_arr.append(i * j)
    result.append(nest_arr)
    nest_arr = []
print(result)

But then again, it all depends on the beginner I guess, this is just another solution with basic Python topics

@Prudent-Gemini
Copy link

Prudent-Gemini commented Feb 19, 2021 via email

@acidsafari
Copy link
Author

I think it's also too complicated if you solve it that way (in my opinion). There's just too much assignment operators and there are some unnecessary variables. For a more Pythonic way while maintaining a beginner's mindset, I'd go for this:

x, y = input().split(",")
result = []
nest_arr = []
for i in range(int(x)):
    for j in range(int(y)):
        nest_arr.append(i * j)
    result.append(nest_arr)
    nest_arr = []
print(result)

But then again, it all depends on the beginner I guess, this is just another solution with basic Python topics

you are right, that code is more Python, thank you!

@acidsafari acidsafari closed this Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants