Can someone please help me write a method?

2009-08-15 4:36 am
Write a checkGuess() method so that it prints a message based on the String parameters, code and guess.

The message it prints will be decided as follows:

• If guess has exactly the same characters as code, then the message printed will be "Correct ".

• Otherwise, if the first character in guess is the same as the first character in code, the method should print "Same first letter".

• Otherwise, the method should print "Incorrect".

(Note: You may assume that both guess and code contain at least one character)

回答 (1)

2009-08-15 4:47 am
✔ 最佳答案
I dont know what language you need to use .

heres a function or subroutine that will do it

def checkguess(guess,code)

if guess = code and len(guess) = len(code) then
msg = "correct"
else if left(guess,1) = left(code,1) then
msg = "Same first letter"
else
msg = "incorrect"

return msg

---------------------------------------------------------------------------

in the main application ou would use msg = checkguess(guess,code)
and print the msg value returned


收錄日期: 2021-05-01 01:07:22
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20090814203629AAu7UVz

檢視 Wayback Machine 備份