Python code help.
|
2014-09-15, 21:26
Post: #1
|
|||||||
|
|||||||
Python code help.
having a little trouble with my code. This will turn out to be a working 'Hangman' game on Python 3.
Problem: I need it to select one random word from the array and allow the user to guess individual letters. the array has been created and it allows you to guess a letter but then stops running.. no need to download it, any advice is valuable to me, since the stuff on the internet is not really helping me where i need to go. https://www.sendspace.com/file/e8bh04 |
|||||||
2014-09-15, 21:30
Post: #2
|
|||||||
|
|||||||
RE: Python code help.
Maybe you have to make a "loop" so that when the user types the letter, it loads the code once again?
Like -At start up: Type the char... -Type the char -Result (Yes/No) + Load the first code -Type the char Just a thought, reading this with my phone ~F |
|||||||
|
|||||||
2014-09-15, 21:32
(This post was last modified: 2014-09-15 21:34 by Carl.)
Post: #3
|
|||||||
|
|||||||
RE: Python code help.
Spoiler (Click to View) |
|||||||
2014-09-16, 00:09
(This post was last modified: 2014-09-16 00:16 by Matt.)
Post: #4
|
|||||||
|
|||||||
RE: Python code help.
Looked at it and just added a three little things.
1) Else argument (if letter is not in the word). 2) Changed letter entry input form to look neater 3) Fixed syntax error (missing colon on if statement) was-input("Ok, make your first guess") now-input("Ok, make your first guess: ") Try having a loop like (Basic python knowledge, beware) input if else loop input Not experimented with that, but in theory it should work. If you want any help just cleaning up the English in this (being a native speaker, I'm willing to help) just ask. https://www.dropbox.com/s/sp2uazpz3m1itm...v2.py?dl=0 |
|||||||
2014-09-16, 06:18
Post: #5
|
|||||||
|
|||||||
RE: Python code help.
Haha thanks Matt, will try it out shortly.
|
|||||||
2014-09-28, 19:27
(This post was last modified: 2014-09-28 19:27 by Carl.)
Post: #6
|
|||||||
|
|||||||
RE: Python code help.
Update.
I struggle to know how the script has chosen the word, and the letters i am guessing are actually going towards a full word? Was not sure if i needed to use a 'for loop' or a 'while loop' when looping the 'guess letter' question? |
|||||||
2014-09-28, 23:24
Post: #7
|
|||||||
|
|||||||
RE: Python code help.
I'd say for...
Also, for a game like hangman, you may be in slightly over your head... Try maybe writing down a list of ways to split it i.e. something like if letter==in whatever you've called your randomly generated word print "Congratulations" but, as far as a way to do this simply is concerned...I'm over my head too. |
|||||||
2014-09-29, 15:23
Post: #8
|
|||||||
|
|||||||
RE: Python code help.
Sidenote-occurred to me today.
While loop... What you want is something like... while x != z (Where x is letter input and z is your randomly generated word" But instead of z you need an embedded if statement to see if said letter (str) is in the word (also str)... |
|||||||
2014-09-29, 19:12
Post: #9
|
|||||||
|
|||||||
RE: Python code help.
Taking note of what you said Matt, i have created this.
file:///C:/Users/htpc2/Downloads/Hangman_v5.py Full file DL: https://www.sendspace.com/file/uwg2p0 The code now recognizes correct and incorrect letters. The code also loops the question over and over 6 times. The code still needs work to allow the guesses to be stringed together and not on separate lines. So if anybody out there, can create some sort of string where the letters will be on the same line that would be appreciated greatly |
|||||||
2014-09-30, 06:17
Post: #10
|
|||||||
|
|||||||
RE: Python code help.
Just a side-note: You can nicely share code (unless its multiple files)
by pasting it online. ie http://pastebin.com/ or http://paste.ubuntu.com/ It's much more comfortable for the reader than this download hassle. |
|||||||
|
|||||||
2014-09-30, 09:10
Post: #11
|
|||||||
|
|||||||
RE: Python code help.
or just use code and /code in here and spoil when it gets too long:
superintelligent code inside (Click to View) just some general advice. always make a good plan or diagram before u even start thinking of coding. that helps alot looking at single chunks part by part. for example ns diagram (Wiki Nassi Shneiderman) or at least just a simple scribble: Quote:The code still needs work to allow the guesses to be stringed together and not on separate lines. not sure if i understand u correctly, but i would go for a dummy. so if your word is "red" u check length(3) crate dummy "___". then something like Code: for i=0 to length(word) also when guessing a letter i would assure that the letter is only a single letter(eg. length=1) and that the letter is not in right_letters or wrong_letters. |
|||||||
|
|||||||
« Next Oldest | Next Newest »
|
Possibly Related Threads... | |||||
Thread: | Author | Replies: | Views: | Last Post | |
code 43 driver not starting | bowler | 2 | 3,173 |
2018-06-04 15:52 Last Post: bowler |
User(s) browsing this thread: 5 Guest(s)
Powered By MyBB, © 2002-2024 MyBB Group