In: Computer Science
Write the code in python only.
You will need the graphics library for this assignment. Please download the library and place it in the same file as your solution.
Draw a 12" ruler on the screen. A ruler is basically a rectangular outline with tick marks extending from the top edge. The tick marks should be drawn at each quarter-inch mark. Below the tick marks, your ruler should show large integers at each full-inch position.
from graphics import * def main(): win = GraphWin('Ruler', 1100, 350) # give title and dimensions rulerLen = 12 eachInchLen = 80 xStart = 70 rect = Rectangle(Point(xStart - 10, 50), Point(10 + xStart + rulerLen * eachInchLen, 100)) rect.setFill("yellow") rect.draw(win) for i in range(13): xS = xStart + i*eachInchLen l = Line(Point(xS, 50), Point(xS, 75)) # set endpoints l.setWidth(2) l.draw(win) label = Text(Point(xS, 90), str(i)) label.draw(win) if i != 12: xS = xStart + i*eachInchLen + eachInchLen/2 l = Line(Point(xS, 50), Point(xS, 70)) # set endpoints l.setWidth(1) l.draw(win) xS = xStart + i*eachInchLen + eachInchLen/4 l = Line(Point(xS, 50), Point(xS, 60)) # set endpoints l.setWidth(1) l.draw(win) xS = xStart + i*eachInchLen + 3*eachInchLen/4 l = Line(Point(xS, 50), Point(xS, 60)) # set endpoints l.setWidth(1) l.draw(win) win.getMouse() win.close() main()
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.