Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For Archers, shooters, hunters, and anyone using an long-range weapon or tool, practicing your aim is important. In this assignment, you will be tasked with
For Archers, shooters, hunters, and anyone using an long-range weapon or tool, practicing your aim is important. In this assignment, you will be tasked with writing a program that prints out a target, and also prints out the locations of various "hits" on this target. The information about where and how the target "hits" should be displayed will be provided by the use via input strings. You should name the file target_practice.py. The program interface This program should accept two strings from the user. The first string specifies where on the targets the program should display the "hits". The target that your program prints out should be a 15-character wide by 11-character tall target, as shown below: The user can tell the program where to put the hit markers on this target using this first input. Each hit should be represented with 4 characters, and the string could have more than one hit. Thus, the length of the string should always be a multiple of 4. Here is one example input string: -2+3+4-1 This input string represents two hits on the target (-2+3 and -4-1). -2+3 means that on the x axis (side to side) the hit should be at negative 2 (two characters left of center) and on the y axis the hit should be at the third level above the middle. +4-1 means that on the x axis the hit should be four characters right of center and on the y axis the hit should be one level above the middle. The second input should be exactly one character long. It represents that character to put onto the target to mark the hit. For example, if the program were run with the first input as -2+3+4-1 and the second input as the string X then it appear as follows: Hit string: -2+3+4-1 Marker: X X Your code should check to ensure that the hit string has a length that is greater than 3, and a multiple of 4. If this is not the case, it should print Please provide a valid hit string. and then continue to ask for the input until a valid one is received. It should also check to ensure that the hit marker has a length of exactly 1. If not, it should print Please provide a valid marker. and then continue to ask for the input until a valid one is received. Printing the Target You are not allowed to use string multiplication for this assignment. Instead, in order to print out the target, I recommend that you use a while loop within a while loop. The "outer" while loop will be responsible for iterating through each row. For this, you can set up a while loop that begins at +5 and iterates until -5. Within this "outer" loop, you can have an "inner" loop that will print out each character on a row, one at a time. There is a rule that will make this easier: The hit marker input string will: (A) Never specify multiple hits on the same row of the target . (B) Specify the hits in order, from top to bottom . (C) Every hit string will have at LEAST one hit Due to this, you can loop through the hit string in-order, and you don't have to concern yourself with printing out multiple hits on the same line. Before we even get to setting up our while loops to print out the rows and characters of this target, we should grab the X/Y position of the first hit and save them into variables. This would look something like: current_hit_x = int(target_string[] + target_string[1]) current_hit_y = int(target_string[2] + target_string[3]) We need two characters for each because we need to account for the or Next, you should write the loops for printing this out. Since string multiplication is not allowed, you will have to write TWO while loops, one inside of the other. The first (outer) loop will be responsible for iterating an index variable from +5 to -5. For example, we could call this index_row. EACH time this loop iterates, we want another loop inside to iterate between -7 and +7, so that we can check each location at the current row. We could call this index_column Each time the inner loop iterates, we need to decide to print one of 4 possible characters: A space, a 0,an or a hit marker. We would print a hit marker whenever index_row == current_hit_y AND index_column -- current_hit_x. If that is not true, then we know we don't have to print out a hit marker. If index_col == @ that indicates we are at the "middle" of our target horizontally, and thus we should print out a 0. Finally, ff index_row -- that indicates we are at the "middle" of our target vertically, and thus we should print out a Example Walkthrough Lets walk through part of an example. Say For EACH row, loop from 7 to that the user ran the program and gave the Begin top-left corner +7 with an INNER while loop Get the X and Y position of the If the number never matches target string +4+4+4+2+3+1+0-2-6-4 and the first hit in the hit string to the X coord of the current hit, begin. character X print a space, unless X coord is zero, print a vertical bar. 1 The code would grab the initial hit x/y as 14 I X When you reach a row that has a hit, make sure to shift to and +4. Then, the outer loop would begin 1 Outer loop, use while loop to the next hit in your hit string! with index_row as 45), and then the inner loop iterate from +5 (top row) to -5 (bottom row) would iterate from 7 to 7 printing out one 1 For middle row, print dashes character at a time. Since there are not hits X instead of spaces. A hit CAN 1 on row 15, no s would print. After the inner be on the target cross loop finishes iterating, the outer loop would 1 repeat again, with index_row now at 14. The 1 inner loop would begin iterating, and would print out a normal target up until the index_column value reaches 14. At this point, index_row == current_hit_y AND index_column == current_hit_x, thus a should be printed. Right after it prints this hashtag, the program should go ahead and change current_hit_x and current_hit_y to the next values in the hit string. Then, continue looping. Basically, this idea repeats for the rest of the target. Rows with no hits end up printing as normal, and rows with hits must print the marker at the correct spot, and then move the current_hit_x and current_hit_y variables to the next values (unless the end of the string has been reached). More Examples Hit string: +5+5+4+4+3+3+2+2+1+1+0+0-1-1-2-2-3-3-4-4-5-5 Marker: # 1 # # 1 # # # 1 1 # + 1 Hit string : +7+5+0+3-4+0+4-3 Marker: Commenting and Style You should also include a comment at the top of the code file. The comment should include your name and a short description of what the program does. Below is a template you may use: ### Author: Your Name Here ### Course: CSC 110 ### Description: Describe your program with one ### or more sentences of text. You should also make sure to follow the style principles shown in the style guidelines
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started