![]() |
|
Python help thread? - 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: Python help thread? (/showthread.php?tid=37777) |
Python help thread? - Alley - 2011-02-12 Does anyone here code in Python? I for serious need some help with a number guessing game. "In this assignment, you'll create a program that plays a simple game. The computer will generate a random integer between 1 and 20, and the user has up to three chances to guess the correct number. If the user guesses the correct number, they are informed of that. If they use all three guesses without guessing the correct number, they are told what the correct number is. Here's a couple of examples of how the game might look (computer in blue, player in black): 1st try. Player correctly guesses the number." Here is what I have so far:
Spoiler
I think that is correct...
Python help thread? - Derosis - 2011-02-12 Lay on your back, with your arms and legs pointed straight. And wait for a corporate executive, Fiel, to come and assist you. Python help thread? - Erebus - 2011-02-12 This is in the funhouse because... Python help thread? - XTOTHEL - 2011-02-12 This part is incorrect: "if n != randint(1,20)" What you're doing here is comparing n which is what they've entered to an random number. You should compare this to "num" which you generated at the beginning of the script. Also it looks like you've only asked the user for the number ONCE but "tried" to evaluate it 3 times with if statements incorrectly. This is what I think that would work... from random import randint num = randint(1,20) for i in range(1, 4): def zenumbers(n): if n != num print "Guess again!" else print "you got it!" break else: print "Used up all 3 guesses" Python help thread? - Alley - 2011-02-12 Oh, sorry about that. I'm a newb, go easy on me. Python is spam to me. Python help thread? - XTOTHEL - 2011-02-12 o-o I don't know what you're sorry about XD, you asked for help. Try the code I presented and see if it works. I don't know python either and I don't have it installed. Python help thread? - Alley - 2011-02-12 XTOTHEL Wrote:o-o I don't know what you're sorry about XD, you asked for help. Try the code I presented and see if it works. I don't know python either and I don't have it installed. No, doesn't work, but thanks for the help! I might just have to break down and actually read this teachers horrible explanations. Python help thread? - XTOTHEL - 2011-02-12 Alley Wrote:No, doesn't work, but thanks for the help! I might just have to break down and actually read this teachers horrible explanations. now? Code: from random import randintPython help thread? - Alley - 2011-02-12 XTOTHEL Wrote:now? You can't have 2 else statements in a definition. Its okay, I'll just copy it from a friend or something.. Thanks for trying.
Python help thread? - XTOTHEL - 2011-02-12 Alley Wrote:You can't have 2 else statements in a definition. Its okay, I'll just copy it from a friend or something.. Thanks for trying. I swear this should work: Code: from random import randintPython help thread? - Eos - 2011-02-12 XTOTHEL Wrote:I swear this should work: It does. the only thing that could've gone wrong is if the indention was copied incorrectly. Python help thread? - XTOTHEL - 2011-02-12 Eosian Wrote:It does. Yea, who knew indentation was so important
Python help thread? - Eos - 2011-02-13 XTOTHEL Wrote:Yea, who knew indentation was so important Anyone who so much as skimmed the Wikipedia opening paragraph on Python
Python help thread? - XTOTHEL - 2011-02-13 Eosian Wrote:Anyone who so much as skimmed the Wikipedia opening paragraph on Python I headed straight for the docs. Python help thread? - Alley - 2011-02-13 XTOTHEL Wrote:Yea, who knew indentation was so important Spending hours getting error messages only to find out that your code was perfect, but you had a secret little indentation. I will swear by this, Python hates gingers. ![]() @Your code. It worked! I did one *major* tweak. The print rnum at the beginning was displaying the secret number.
Python help thread? - Eos - 2011-02-13 Alley Wrote:@Your code. It worked! I did one *major* That was for debugging purposes so you could tell if it was working correctly. It was never meant to be left in once you validated it did what you wanted. Python help thread? - ThatWasMyKil - 2011-02-16 This makes me hot. please continue. Python help thread? - AngelSL - 2011-03-01 Alley Wrote:You can't have 2 else statements in a definition. Its okay, I'll just copy it from a friend or something.. Thanks for trying. Confusing, but an else statement after a for loop in Python, is syntactic sugar for lines that should execute if and only if the loop executed without break-ing. Python help thread? - EarthAdept2 - 2011-03-04 Can someone quickly double check this: Assumptions: Only valid number inputs for the range. That is, no floating point values, letters and the like. Result that comes out of this code should be exactly the same as this: Code: Do you want to play ('y' for yes)? yCode: import randomI did add some of my own stuff in there for additional dummy proofing. But it shouldn't change the output result should you enter in the same stuff as the required input. Python help thread? - JPTheMonkey - 2011-03-04 Okay, so I have a new assignment in class to write a program that translates a word into pig latin. From what I've seen by the examples, a word beginning with 2 consonants should be translated up to the first vowel and have the consonants that were removed appear in front of the "ay" but I have no clue how to get past the first. Any ideas? Code: from string import *Also @above: Why do you use int(raw_input())? input() works just the same as that. |