Sounds like a homework question, but since you posted your work. I may help you.
Ordinarily homework is strictly forbidden on this site.
You must give more info first. What Operating System, what shell are you using, what programming language are you using.
If it is ksh or sh or bash, put the password in a file and call the file from the command line. Most types of scripting will support this function.
OR you might put the whole thing in file and make it executable "chmod 755 filename" and the "./filename" to execute it.
What is the purpose of the is assignment. Are you just changing a user's password and that's it or are you using a password for a program?
That would be helpful as well.
And in the future, try not to post homework, if this is that.