Python Forum
Need help with a tough school assignment
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:
[Image: photo.php?fbid=10159073980579572&set=a.1...=3&theater]
Reply
#2
What have you tried so far?
Reply
#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
Reply
#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()
Reply
#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.
Reply
#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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  School Work Assignment: Snake Game DarksideMoses 6 5,088 Apr-29-2018, 10:56 PM
Last Post: DarksideMoses
  Array to get profit (school assignment) harryvandervelden 2 2,786 Nov-28-2017, 05:48 PM
Last Post: Larz60+
  School assignment Ronaldo 5 9,013 Jan-08-2017, 11:57 AM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020