0

A code that will ask for the list length, & also ask for the user to input until the number of the input==length of the list

15th Sep 2018, 10:03 AM
Joseph Ojo
Joseph Ojo - avatar
8 RĂ©ponses
+ 4
The purpose of the Q&A is to help with particular coding problems. So the questions should be: (A) something like this: "I'm trying to write some code to do X. [describe] This is what I've tried. [post link to your code] But this is what happens. [describe problem] What am I doing wrong?" (B) not like this: "Write some code for me that does X." You will find that people will leap to your aid if you ask like (A), but if you ask like (B), not so much 😉 Tip: Use the Q&A search feature and/or Google first. Chances are you'll find your answer there. 😊
15th Sep 2018, 10:52 AM
David Ashton
David Ashton - avatar
+ 4
For the part I think you mean, as i gets larger, the final value of j gets smaller. Here's another way: def bubbleSort(alist): for passnum in range(len(alist)-1,0,-1): for i in range(passnum): if alist[i]>alist[i+1]: temp = alist[i] alist[i] = alist[i+1] alist[i+1] = temp alist = [54,26,93,17,77,31,44,55,20] bubbleSort(alist) print(alist)
15th Sep 2018, 12:23 PM
David Ashton
David Ashton - avatar
+ 1
Please provide a link to your Code Playground code (water molecule icon in the upper right) so we can help you troubleshoot the specific issues you are running into. It looks like you may have already found the Code Playground, but just as a reminder, it should be relatively easy to find in the website version of SoloLearn, and if you are in the app version, it can be accessed via the curly braces, green circle with plus sign to add a new project, then select the project type. Looking forward.
15th Sep 2018, 10:18 AM
Janning⭐
Janning⭐ - avatar
+ 1
thank you
15th Sep 2018, 12:24 PM
Joseph Ojo
Joseph Ojo - avatar
0
sololearn is opened on my phone and I'm using atom on my PC, that's why there was no link...and I'll keep that in mind next time Dave and janning, hope you will explain the second part i put into other languages multi-line comment https://code.sololearn.com/cbU0WdE1PzE6/?ref=app
15th Sep 2018, 11:30 AM
Joseph Ojo
Joseph Ojo - avatar
0
This seems overly complicated for what I think you're looking for based on my reading of your original post. Is the user providing the length of the array through input or are you "asking" another piece of code?
15th Sep 2018, 12:19 PM
Janning⭐
Janning⭐ - avatar
0
what I asked for originally, is the first part of bubbleSort, coz the user will have to specify the length, then input the values in the list, the first piece I put into multi-line comment does that
15th Sep 2018, 12:22 PM
Joseph Ojo
Joseph Ojo - avatar
0
The secret motives were revealed! :) Elegant code, David Ashton. 👍 Here's the lesson's version: https://www.sololearn.com/learn/701/?ref=app
15th Sep 2018, 12:30 PM
Janning⭐
Janning⭐ - avatar