Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with a tough school assignment
hi everyone

i have some school that i really need help with .
- how do i start to do the coding
- and how do i create the function needed to work out the ans .
The problem:
What have you tried so far?
And please don't paste images. Instead use python and output tags when posting code and results. Here are instructions on how to use them.
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

My code dont see to be working , please help me :0

import random
def checkguess(guessword,maskString,userinput): 
    updateStr = ""
    for i in range(0,len(guessword)):
        if guessword[i] == userinput:
            updateStr=updateStr + updateStr[i]
            updateStr=updateStr + maskString[i]
    return updateStr
def q4():
     wordlist = "meringue foulard eudaemonic narcolepsy vivisepulture pococurante albumen cymotrichous malfeasance "
     words = wordlist.split()
     index = random.randint(0,len(words)-1)
     print(words[index])#for error checking
     guessword = words[index]
     lettercount = len(words[index])   
     maskString = "_ "*len(words[index])
     print("The word {:} has {:} letters . Spell it in 5 tries." .format(maskString,lettercount ))
     currentTry = 1
     while currentTry < 6:
         print ("Try {} - Current :{}".format(currentTry,maskString))
         userinput = eval(input("your guess ? : "))
         maskString = checkguess(guessword,maskString,inputData)
         currentTry +=1 
         if maskString == guessword:
     print("correct the words is :",guessword)        
ichabod801 wrote Feb-18-2019, 05:54 PM:
Please use python and output tags when posting code and results. I put them in for you this time. Here are instructions for doing it yourself next time.

This is the second time I have told you about this. If I have to do it again I will start issuing warnings.
Start by printing what is happening at checkpoints. So, for example, if you are comparing the input letter to the guessword letter, print both of then to see what you are comparing, and the same for other checkpoints in the program.
Just glancing at the code, I would say don't eval the input, that will just cause name errors. Also, on line 5, you are comparing one character of guessword to the whole of userinput, so I doubt that ever works correctly. Finally, note that maskString is twice as long as guessword. So you can't use indexes on that the way you are using indexes on the other words.

That brings me to something that is bad coding practice, although it may not be preventing you code from working. You should iterate over the strings, not the indexes of the strings, as shown here.
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Help with assignment dxfrelince 7 185 Feb-18-2019, 09:16 PM
Last Post: dxfrelince
  Help with arrays assignment hyg71886 15 248 Jan-30-2019, 09:36 AM
Last Post: perfringo
  Python Assignment 5.2 amos76823 3 258 Jan-17-2019, 07:34 AM
Last Post: perfringo
  Python for Everybody 3.3 assignment ramadan2099 5 283 Jan-09-2019, 09:10 PM
Last Post: ramadan2099
  Python for Everybody 3.1 assignment ramadan2099 14 515 Jan-07-2019, 07:31 PM
Last Post: ramadan2099
  card dealer school project kalle1234 5 247 Jan-05-2019, 09:21 PM
Last Post: ichabod801
  Help for my assignment - Object Oriented Programming denizkb 5 210 Jan-05-2019, 06:43 PM
Last Post: stullis
  [split] Python for Everybody 5.2 assignment ramadan2099 2 256 Jan-05-2019, 12:54 PM
Last Post: ramadan2099
  help with assignment 3 Mof44 5 265 Dec-14-2018, 01:33 PM
Last Post: Mof44
  help with assignment 2 Mof44 4 301 Nov-29-2018, 08:26 PM
Last Post: Mof44

Forum Jump:

Users browsing this thread: 1 Guest(s)