![]() |
|
Time to get started on Python homework... - Printable Version +- Southperry.net (https://www.southperry.net) +-- Forum: Social (https://www.southperry.net/forumdisplay.php?fid=14) +--- Forum: Rubik's Cube (https://www.southperry.net/forumdisplay.php?fid=58) +--- Thread: Time to get started on Python homework... (/showthread.php?tid=47655) Pages:
1
2
|
Time to get started on Python homework... - Alley - 2011-10-06 Can I get some sort of jumpstart with a python script? I've been on this same project for over a year and can't for the life of me seem to get started on it.. ![]() Code: The assignment: You've been hired to write a program that will choose random lottery numbers for the Lotto 6-49. Your program should create a list of 6 different random numbers in the range of 1 to 49, then print them all out on one line.He says it has to do with "structured data" in a program. Any help would be appreciated. Time to get started on Python homework... - Kalovale - 2011-10-06 import random Then look up its documentations for RNG features. Depending on the specific requirements (numbers repeating, non-repeating adjacents, such and such...), figure out an appropriate way to do it. By data structures, I assume your teacher/whoever wants you to use arrays and/or lists, which are what I'd use if the numbers don't repeat themselves. As for printing everything out in one line, I *think* an efficient way is to concatenate the sub-results into a final string to be output. If I'm not mistaken, concatenating string in Python involves only a + operator. Time to get started on Python homework... - Heidi - 2011-10-06 Is it okay for you to use pseudo random numbers for this assignment? Overall, this sounds like a really really simple program, probably only a few lines of code unless I'm seriously missing something... Time to get started on Python homework... - Kalovale - 2011-10-06 Heidi Wrote:Is it okay for you to use pseudo random numbers for this assignment? Do you have any other approach to generate random sequences of items? I'm curious how this can be done without an RNG. :f6: Time to get started on Python homework... - Alley - 2011-10-06 Jesus, I should have really started this when python was still fresh in my brain... None of this is making sense to me.. Time to get started on Python homework... - Heidi - 2011-10-06 Kalovale Wrote:Do you have any other approach to generate random sequences of items? I'm curious how this can be done without an RNG. :f6: Obviously a RNG of some kind has to be used. Whether or not it is a PRNG is the question. It could be possible to interface with something like this site http://www.random.org/ Although I'd say that's beyond the scope of Alloy's assignment. Time to get started on Python homework... - Fiel - 2011-10-06 Code: import randomTime to get started on Python homework... - Alley - 2011-10-06 Wow.. Now I feel retarded. Time to get started on Python homework... - Kalovale - 2011-10-06 Alley Wrote:Wow.. Now I feel retarded. I'll try to dissect Fiel's algorithm.
Spoiler
Time to get started on Python homework... - Fiel - 2011-10-06 range(1, 50) creates a range from [1, 50) Here's a more Python noob-friendly way of doing it. Code: import randomTime to get started on Python homework... - Kalovale - 2011-10-06 Fiel Wrote:range(1, 50) creates a range from [1, 50) Why are the endpoints so inconsistent... Time to get started on Python homework... - Heidi - 2011-10-06 Python is a bit strange with endpoints compared to other languages. You'll just have to get used to that. :-) And keep in mind that if you are unsure about what values will be in a list or something, such as endpoints, just experiment by typing commands into the python interpreter. Interpreters are great for learning and understanding programming languages. Time to get started on Python homework... - Kalovale - 2011-10-06 Experimenting is the spirit of learning this business anyway. It'd just be helpful if you can make reasonable assumptions here and there instead of having to rely on empirical experience. Time to get started on Python homework... - Alley - 2011-10-07 Fiel Wrote:range(1, 50) creates a range from [1, 50) Yeah, that'll probably make my teacher less hard, thus less suspicious. Looks like something I would come up with, thanks Fiel
Time to get started on Python homework... - Alley - 2011-10-22 I hate to double post, but I didn't want to start a new thread. Here is the second part of this assignment: Code: Your previous lottery number generator would work for selecting Lotto 6/49 numbers but other lotteries use different sets of numbers and different lengths of lists. It would be much more useful if we could have a program that would let the user input the minimum and maximum values for the random generated numbers as well as the number of random numbers needed, like this:Now my brainstorming got me to the point of using inputs in place of the min and max(1, 50) and the number of numbers(:6), I tired using variables for them, but I guess I'm too much of a noob to do any of this.. Also, I have no idea of where to use this "numlist" he speaks of. Time to get started on Python homework... - Heidi - 2011-10-22 numlist is just a function you have to write... Were you taught about this stuff in the class you were given the homework in? This is very basic stuff here. Time to get started on Python homework... - Alley - 2011-10-22 Not at all. He gives us these very long pages to read, and really none of it coincides with the homework. Time to get started on Python homework... - Heidi - 2011-10-22 So does it mention about what functions, parameters, return values, etc are? Time to get started on Python homework... - Kalovale - 2011-10-22 Heidi Wrote:So does it mention about what functions, parameters, return values, etc are? Considering the pages being "very long", I'd assume yes. Who could write pages on introduction to programming without those concepts? Anyway, this is how you do it: Instead of explicitly declaring the values like Fiel did here Code: while len(randomNumbers) < 6:Code: randomNumber = random.randint(1, 49)Code: while len(randomNumbers) < totalLotteryLength:Code: randomNumber = random.randint(1, UpperRandomNumberLimit)Where do you get these numbers? From the user, as instructed. So ask the user for the inputs and store their answers into the variables. Time to get started on Python homework... - Alley - 2011-10-23 Can I have two variable in randomNumber? As in: Code: randomNumber = random.randint(LowerRandomNumberLimit, UpperRandomNumberLimit) |