[Solved] CSCI1100 Homework 3 If statements, Modules, Lists and While Loops

$25

File Name: CSCI1100_Homework_3_If_statements__Modules__Lists_and_While_Loops.zip
File Size: 612.3 KB

SKU: [Solved] CSCI1100 Homework 3 If statements, Modules, Lists and While Loops Category: Tag:
5/5 - (1 vote)

In this homework, we will be making use of a module called hw3_util.py that provides a functionfor this part of the homework. To get started with this part, unzip the folder given to you containingthe input files and this util file. You will start with reading the file containing information aboutteams in the championship league. Try the following:import hw3_utilteams = hw3_util.read_fifa()print teams[0]The function called read_fifa() will return you a list of teams. Each item in the list is informationfor a team given in a list containing the following information:[team, games_played, win, draw, lose, goals for, goals against]Write a program to compare any two teams from this list and to print which team is superior. Hereare the rules: The team with the highest points is superior. Points are calculated as follows: each win is 3points and each draw is 1 points. If the points are the same, then the team with the higher goal difference is superior. The goaldifference is compuated as follows: subtract the number of goals against from the number ofgoals scored. If the two teams have the same goal difference, then the team with the higher number of g4Team Win Draw Lose GF GA Pts GDWest Bromwich Albion13 8 17 45 52 47 -7Swansea City 12 11 15 44 51 47 -7West Bromwich Albion is betterWhen you have tested your code, please submit it as hw3_part1.py. Do not submit the input fileor the utility module we gave you. Homework server will supply them.Part 2: Turtle moves!Suppose you have a Turtle that is standing in the middle of an image, at coordinates (200,200)facing right (along the dimensions). Assume top left corner of the board is (0,0) like in the images.You are going to read input from the user five times. Though you do not have to use a loop forthis part, it will considerably shorten your code to use one. It is highly recommended that you usea loop here.Each user input will be a command to the Turtle. You are going to execute each command as it isentered, print the Turtles current location and direction. At the same time, you are going to putall the given commands in a list, sort this resulting list at the end of the program and print it asis (no other formatting).Here are the allowed commands: move will move Turtle 20 steps in its current direction. jump will move Turtle 50 steps in its current direction. turn will turn the Turtle 90 degrees counterclockwise: right, up, left, down.If user enters an incorrect command, you will do nothing and skip that command. You shouldaccept commands in a case insensitive way (move, MOVE, mOve should all work).You must implement two functions for this program: move(x,y,direction,amount)will return the next location of the Turtle as an (x,y) tuple if it is currently at (x,y), facingdirection (direction one of right, up, left, down) and moves the given amount. turn(direction)will return the next direction for the Turtle currently facing direction, moving counterclockwise.Now, write some code that will call these functions for each command entered and update thelocation of the Turtle accordingly. Here is an example run of the program:Turtle: (200,200) facing: rightCommand (move,jump,turn) = turrnturrnTurtle: (200,200) facing: rightCommand (move,jump,turn) = turnturnTurtle: (200,200) facing: upCommand (move,jump,turn) = MoveMoveTurtle: (200,180) facing: upCommand (move,jump,turn) = turnturnTurtle: (200,180) facing: leftCommand (move,jump,turn) = jumPjumPTurtle: (150,180) facing: leftAll commands entered [turrn, turn, Move, turn, jumP]Sorted commands [Move, jumP, turn, turn, turrn]In the above example, turrn is an invalid command, so it has no effect in the Turtles state. In caseyou are wondering, the list is sorted by string ordering, which is called lexicographic (or dictionary)ordering.When you have tested your code, please submit it as hw3_part2.py.Part 3: Return of the boxIn this part of the homework, you will do a variation of the box problem. As you have now becomea CS1 master, this part is substantially more difficult. You will read the height of a box and printa diamond of this height (with line numbers on the left side). You will also ask for the foregroundand background characters to use in the printing.You will also do some error checking in this case. You will print an error message for each error.If there are no errors, only then, you will print the box. Here are the errors you should check inthis order (assume that if height is a digit it is at least 7 and do not check this one as we have notlearnt nested if statements yet):1. Is the height a number? Check using str.isdigit() and if not printPlease enter a number for height.2. Is the background character is a single character? If not printPlease enter one character for background.3. Is the foreground character a single character? If not printPlease enter one character for foreground.Here is a possible run of the program on Wing IDE:Background char = ..Foreground char = @@Height = 771[email protected]@.2@[email protected]3[email protected].o..4[email protected]@.5[email protected][email protected]..6@[email protected]7[email protected]@.We have analyzed the technical specifications for the diamond and found a significant flaw: online 3, there is a single o at the end of the diamond, instead of the foreground character. Thisincorrect character appears on the third line of the diamond regardless of its height. Your codemust replicate this flaw.Your output must match ours for full credit, but there will be lots of partial credit. Note a fewthings: The diamond is padded with the background character on the left and right (starting withheight number of characters on each side of the diamond.) When the height is even, we repeat the middle line. The line numbers are right justified. When the max line number is double digit, then singledigit line numbers are padded with a space on the left (I used str.rjust(2) for this, seebelow for examples.) Clearly, you need loops. Think about first writing a loop to do top part of the diamond.Then, write a separate loop for the bottom part. Then, finally add a few if statements tohandle the special cases.Here are some other possible outputs:Background char =Foreground char = **Height = 881 **2 * *3 * o4 * *5 * *6 * *7 * *8 **Background char = ..Foreground char = @@Height = 12121@@2[email protected]@..3[email protected].o.4@@5[email protected][email protected]..6[email protected][email protected].7[email protected][email protected].8[email protected][email protected]..9@@10[email protected][email protected].11[email protected]@..12@@Also, error handling:Background char = ababForeground char = cdcdHeight = efefPlease enter a number for heightPlease enter one character for backgroundPlease enter one character for foregroundWhen you have tested your code, please submit it as hw3_part3.py.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSCI1100 Homework 3 If statements, Modules, Lists and While Loops[Solved] CSCI1100 Homework 3 If statements, Modules, Lists and While Loops
$25