Python Forum
Need help with a tough school assignment - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Need help with a tough school assignment (/thread-15947.html)



Need help with a tough school assignment - datson79 - Feb-07-2019

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:
[Image: photo.php?fbid=10159073980579572&set=a.1...=3&theater]


RE: Need help with a tough school assignment - Kebap - Feb-07-2019

What have you tried so far?


RE: Need help with a tough school assignment - ichabod801 - Feb-07-2019

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.


RE: Need help with a tough school assignment - datson79 - Feb-18-2019

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]
        else:
            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:
             break
         
    
     print("correct the words is :",guessword)        
        
q4()



RE: Need help with a tough school assignment - woooee - Feb-18-2019

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.


RE: Need help with a tough school assignment - ichabod801 - Feb-18-2019

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.