<html>
<head>
<meta name="generator" content="Windows Mail 17.5.9600.20689">
<style data-externalstyle="true"><!--
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
}
p.MsoNormal, li.MsoNormal, div.MsoNormal {
margin:0in;
margin-bottom:.0001pt;
}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst, 
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle, 
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
line-height:115%;
}
--></style></head>
<body dir="ltr">
<div data-externalstyle="false" dir="ltr" style="font-family: 'Calibri', 'Segoe UI', 'Meiryo', 'Microsoft YaHei UI', 'Microsoft JhengHei UI', 'Malgun Gothic', 'sans-serif';font-size:12pt;"><div>I am not understanding how I am supposed to do the highlighted things on the problem statement. If someone could please direct me on the steps to go about doing what is highlighted.  Have do I read each command, by making the program read each line?? How do I add the invalid commands into a set? When printing the command is invalid, do I simply do as I did with the valid commands print?</div><div><br></div><div>Problem Statement: <font face="Times New Roman">

</font><p style="margin: 0in 0in 8pt;"><font face="Calibri Regular">We are going to write a program that reads an input file of
commands (Commands.txt) to Arnold the Robot.</font></p><font face="Times New Roman">

</font><p style="margin: 12pt 0in 0pt;"><font face="Calibri Regular">The four valid command are:</font></p><font face="Times New Roman">

</font><ul style="padding-top: 0px; padding-bottom: 0px; margin-top: 0px; margin-bottom: 0px; list-style-type: disc; direction: ltr;"><li style="color: rgb(0, 0, 0); font-size: 11pt; font-style: normal; font-weight: normal;"><p style="color: rgb(0, 0, 0); line-height: normal; font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 0in; margin-bottom: 0pt; mso-add-space: auto; mso-list: l1 level1 lfo2;">Up</p></li><li style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal;'><p style='color: rgb(0, 0, 0); line-height: normal; font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 12pt; margin-bottom: 0pt; mso-add-space: auto; mso-list: l1 level1 lfo2;'>Down</p></li><li style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal;'><p style='color: rgb(0, 0, 0); line-height: normal; font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 12pt; margin-bottom: 0pt; mso-add-space: auto; mso-list: l1 level1 lfo2;'>Left </p></li><li style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal;'><p style='color: rgb(0, 0, 0); line-height: normal; font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 12pt; margin-bottom: 0pt; mso-add-space: auto; mso-list: l1 level1 lfo2;'>Right </p></li></ul><font face="Times New Roman">







</font><p style="margin: 12pt 0in 8pt;"><font face="Calibri Regular"><font style="background-color: rgb(0, 255, 0);">After you read each command</font>, make
sure it is valid (included in the </font><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;"><font face="Calibri Bold Italic">set</font></i></b><font face="Calibri Regular"> of valid commands).</font></p><font face="Times New Roman">

</font><p style="margin: 0in 0in 8pt;"><font face="Calibri Regular">If the command is valid, print “Valid command entered, the
command was:” and the command.</font></p><font face="Times New Roman">

</font><p style="margin: 0in 0in 8pt;"><font face="Calibri Regular"><font style="background-color: rgb(0, 255, 0);">If the command is invalid, print “Invalid command entered, the
command was:” and the command</font><font style="background-color: rgb(0, 255, 0);">.</font></font></p><font face="Times New Roman">

</font><p style="margin: 0in 0in 8pt;"><font face="Calibri Regular" style="background-color: rgb(0, 255, 0);">If the command is invalid, add it to a </font><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;"><font face="Calibri Bold Italic" style="background-color: rgb(0, 255, 0);">set</font></i></b><font face="Calibri Regular" style="background-color: rgb(0, 255, 0);"> of invalid commands.</font></p><font face="Times New Roman">

</font><p style="margin: 0in 0in 0pt;"><font face="Calibri Regular">Keep a count
of:</font></p><font face="Times New Roman">

</font><ol style="padding-top: 0px; padding-bottom: 0px; margin-top: 0px; margin-bottom: 0px; list-style-type: decimal; direction: ltr;"><li style="color: rgb(0, 0, 0); font-size: 11pt; font-style: normal; font-weight: normal;"><p style="color: rgb(0, 0, 0); font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 0in; margin-bottom: 0pt; mso-add-space: auto; mso-list: l0 level1 lfo3;">The total number of commands read</p></li><li style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal;'><p style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 0in; margin-bottom: 0pt; mso-add-space: auto; mso-list: l0 level1 lfo3;'>The total number of valid commands read</p></li><li style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal;'><p style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 0in; margin-bottom: 8pt; mso-add-space: auto; mso-list: l0 level1 lfo3;'>The total number of invalid commands read</p></li></ol><font face="Times New Roman">





</font><p style="margin: 0in 0in 0pt;"><font face="Calibri Regular">After all of
the commands have been read:</font></p><font face="Times New Roman">

</font><ol style="padding-top: 0px; padding-bottom: 0px; margin-top: 0px; margin-bottom: 0px; list-style-type: decimal; direction: ltr;"><li style="color: rgb(0, 0, 0); font-size: 11pt; font-style: normal; font-weight: normal;"><p style="color: rgb(0, 0, 0); font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 0in; margin-bottom: 0pt; mso-add-space: auto; mso-list: l3 level1 lfo4;">Print the total number of commands read</p></li><li style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal;'><p style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 0in; margin-bottom: 0pt; mso-add-space: auto; mso-list: l3 level1 lfo4;'>Print the total number of valid commands read</p></li><li style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal;'><p style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 0in; margin-bottom: 0pt; mso-add-space: auto; mso-list: l3 level1 lfo4;'>Print the total number of invalid commands read</p></li><li style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal;'><p style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 0in; margin-bottom: 0pt; mso-add-space: auto; mso-list: l3 level1 lfo4;'>Print the number of unique invalid commands read</p></li><li style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal;'><p style='color: rgb(0, 0, 0); font-family: "Calibri",sans-serif; font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 0in; margin-bottom: 8pt; mso-add-space: auto; mso-list: l3 level1 lfo4;'>Print the set of invalid commands.</p></li></ol><font face="Times New Roman">









</font><p style="margin: 0in 0in 0pt;"><font face="Calibri Regular">The format
of the input files is:</font></p><font face="Times New Roman">

</font><ol style="padding-top: 0px; padding-bottom: 0px; margin-top: 0px; margin-bottom: 0px; list-style-type: decimal; direction: ltr;"><li style="color: rgb(0, 0, 0); font-size: 11pt; font-style: normal; font-weight: normal;"><p style="color: rgb(0, 0, 0); font-size: 11pt; font-style: normal; font-weight: normal; margin-top: 0in; margin-bottom: 8pt; mso-list: l2 level1 lfo1;">Each line in the file contains a command, not
all command are valid</p></li></ol><font face="Times New Roman">

</font><br></div><div data-signatureblock="true"><div><br></div><div>My Code So Far:</div><div>def main() : <br>   # Define main variables<br>       leftCount = 0<br>       rightCount = 0<br>       upCount = 0<br>       downCount = 0<br>       commandCount = 0<br>       invalidCommands = 0   <br>       command = ("left", "right", "up", "down")<br>       numUnique = 0<br>       numInvalid = 0<br>       invalidCommands = set()<br>       <br>       filename = input("Enter filename (default: Commands.txt): ") <br>       if len(filename) == 0 : <br>              filename = "Commands.txt" <br>       inputFile = open(filename, "r")<br>       <br>       <br>       command = input("Please enter a command for Arnold: ")<br>       if command in command :<br>                     commandCount = commandCount + 1<br>                     print("The total amount of commands: ", commandCount)<br>       if command == "up" :<br>                     upCount = upCount + 1<br>                     print("Valid command entered, the command was: up")<br>       elif command == "down" :<br>                     downCount = downCount + 1<br>                     print("Valid command entered, the command was: down")<br>       elif command == "left" :<br>              leftCount = leftCount + 1<br>              print("Valid command entered, the command was: left")<br>       elif command == "right" :<br>              rightCount = rightCount + 1<br>              print("Valid command entered, the command was: right")<br>       else :<br>              print("Invalid command entered, the command entered was: ", command)<br>              numInvalid = numInvalid + 1<br>              if not command in invalidCommands :<br>                     numUnique = numUnique + 1<br>              invalidCommands.add(command)       <br>   <br>       <br>      <br>                <br>       <br>       for line in inputFile :<br>              theWords = line.split()<br>              for word in theWords :<br>                     cleaned = clean(word)<br>              if cleaned != "" :<br>                     numUnique.append(cleaned) <br>       print("The file contains", len(numUnique), "unique words.") <br>       </div><div><br></div><div># Cleans a string by making letters lowercase and removing characters that are not letters<br>#  @param string the string to be cleaned <br>#  @return the cleaned string <br>def clean(string) : <br>       result = "" <br>       for char in string : <br>              if char.isalpha() : <br>                     result = result + char <br>                     return result.lower() </div><div><br></div><div><br></div><div><br></div><div><br># Start the program. <br>main()</div><div><br></div><div><br></div><div>What Happens When Ran:</div><div>3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)]<br>Python Type "help", "copyright", "credits" or "license" for more information.<br>[evaluate CommandsDraft.py]<br>Enter filename (default: Commands.txt): Commands.txt<br>Please enter a command for Arnold: dawn<br>The total amount of commands:  1<br>Invalid<br>Traceback (most recent call last):<br>  File "C:\Program Files (x86)\Wing IDE 101 5.0\src\debug\tserver\_sandbox.py", line 70, in <module><br>  File "C:\Program Files (x86)\Wing IDE 101 5.0\src\debug\tserver\_sandbox.py", line 52, in main<br>builtins.AttributeError: 'int' object has no attribute 'append'</div><div><br></div></div></div>
</body>
</html>