Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Need help with a tough school assignment
#1
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:
İmage
Quote
#2
What have you tried so far?
Quote
#3
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 - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#4
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()
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.
Quote
#5
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.
Quote
#6
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 - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [split] Python for Everybody 5.2 assignment jonchanzw 2 279 Jun-14-2019, 09:45 PM
Last Post: nilamo
  assignment help sammmy 4 309 Jun-11-2019, 06:17 PM
Last Post: micseydel
  Write pseudo code for a class assignment Scrimshot 3 297 May-07-2019, 05:38 PM
Last Post: Scrimshot
  School projet robalexx 1 221 May-03-2019, 10:41 AM
Last Post: heiner55
  Need help with my assignment please - game of Solitaire Muzz 2 337 Apr-09-2019, 03:48 PM
Last Post: Muzz
  [Tkinter] Tkinter project school Kersow 2 185 Apr-08-2019, 08:45 PM
Last Post: Larz60+
  [split] University Assignment Help needed Nomathemba 2 206 Apr-07-2019, 11:49 PM
Last Post: micseydel
  Powerball assignment, how to get correct output of a dictionary ? msp1981 5 290 Mar-19-2019, 11:02 PM
Last Post: Yoriz
  Help with homework assignment grayarea3 1 351 Feb-20-2019, 10:10 PM
Last Post: ichabod801
  Help with assignment dxfrelince 7 519 Feb-18-2019, 09:16 PM
Last Post: dxfrelince

Forum Jump:


Users browsing this thread: 1 Guest(s)