python - What is the correct way to use a .join() function? -


so new coding , part of course making hangman game. when run program, says "['', '', '', '', '', '', '', ''] input : ". want make apostrophes , commas not printed. feel .join() function best way this, still learning, not sure how and/or place function. please bear me! thank you!!

original=list(word) temp=list(word) guess=[] #null list lettersguessed=[] trial=int(0) #for keeping track of guessess userinput='' counter=int(0) #keeping track of position of element in list (if found) letterlist=['abcdefghijklmnopqrstuvwxyz']   in range(len(original)): #creating '_ _**....' list     if (original[i]==' '):         guess.append(" ") #(whitespace) vowels     else:         guess.append("_") #_ other alphabets 

i think got want. moved if statement of used letters top of while, , instead of appending lettersguessed guess variable, appended userinput variable.

print "welcome hangman!"  print '                                            '  print '------------------------------------------'  print '                                            '  import random #for random.choice dictionary=['coding', 'genepeeks', 'python', 'free tom brady', 'boston'] word=random.choice(dictionary) original=list(word) temp=list(word) guess=[] #null list lettersguessed=[] trial=int(0) #for keeping track of guessess userinput='' counter=int(0) #keeping track of position of element in list (if found)   in range(len(original)): #creating '_ _**....' list     if (original[i]==' '):         guess.append(" ") #(whitespace) vowels     else:         guess.append("_") #_ other alphabets  print guess  while trial<15:     userinput=str.upper(raw_input('input : '))      if userinput in lettersguessed:  # test presence         print "this letter has been used already!"         continue     else:         lettersguessed.append(userinput) # remember used      if len(userinput)>1: #checking multiple characters         print 'error : input single character'         trial -= 1         continue      if userinput in original:         while userinput in temp: #loop checking redundant characters             counter=temp.index(userinput)             guess[counter]=userinput             temp.remove(userinput)             temp.insert(counter,'_')          counter=0          in range(0,len(temp)): #checking final guess match original             if temp[i]=='_':                 counter+=1            if counter==len(original): #if guess matches original             print 'correct\t', guess             print 'you win !'             trial=10             break          print 'correct\t' , guess , '\ttrials left: ', (9-trial)      else:         trial+=1         print 'incorrect', '\ttrials left: ', (9-trial) else:     print 'you lose !'     print 'correct answer was\t', original 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -