Question

In: Computer Science

Write this code in Python only. Draw a 12" ruler on the screen. A ruler is...

Write this code in Python only.

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.

Solutions

Expert Solution

def draw_line(tick_len, tick_label):
        print('-'*tick_len, tick_label)

def draw_ruler(length, tick_count):
        if length > 0:
                draw_line(tick_count, '0')
        helper(1, length, tick_count)

def drawSegment(max_len):
        if(max_len == 1):
                draw_line(1, '')
        else:
                drawSegment(max_len - 1)
                draw_line(max_len, '')
                drawSegment(max_len - 1)


def helper(start, max_length, ticks):
        if(start > max_length):
                return
        drawSegment(ticks - 1)
        draw_line(ticks, str(start))
        helper(start+1, max_length, ticks)

draw_ruler(12, 3)
**************************************************

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.


Related Solutions

Use python programming to write this code and provide a screen short for the code. 2....
Use python programming to write this code and provide a screen short for the code. 2. Write a function that takes one argument (a string) and returns a string consisting of the single character from that string with the largest value. Your function should contain a for loop. You can assume that the input to your function will always be a valid string consisting of at least one character. You can assume that the string will consist only of lower-case...
Write the code in python only. You will need the graphics library for this assignment. Please...
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.
python Write a program that prints your name 100 times to the screen. Write a function...
python Write a program that prints your name 100 times to the screen. Write a function that takes a string s and an integer n as parameters and prints the string s a total of n times (once per line). Write a for loop that prints all the integers from 3141 to 5926, skipping every other one. Write a for loop that prints every 5th integer from 5926 down to 3141. Write a program (using a for loop) to print...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file....
Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file. Postfix Expression                Result 4 5 7 2 + - * = -16 3 4 + 2  * 7 / = 2 5 7 + 6 2 -  * = 48 4 2 3 5 1 - + * + = 18    List as Stack """ File: pyStackPostfix.py Author: JD """ # 5 7 + 6 2 -  * = 48 print("Postfix Calculator\n") stack = []              # Empty stack...
please answer this in a simple python code 1. Write a Python program to construct the...
please answer this in a simple python code 1. Write a Python program to construct the following pattern (with alphabets in the reverse order). It will print the following if input is 5 that is, print z one time, y two times … v five times. The maximum value of n is 26. z yy xxx wwww vvvvvv
Using Python code create a program only with beginners code. You are taking online reservations at...
Using Python code create a program only with beginners code. You are taking online reservations at the The inn Ask for your client’s name and save in a variable Ask how many nights your client will be staying and save in a variable Room rental is $145 per night Sales tax is 8.5% Habitation tax is $5 per night (not subject to sales tax) Print out: Client’s name Room rate per night Number of nights Room cost (room rate *...
Python regex How to write the regex in Python that only include the contents within a...
Python regex How to write the regex in Python that only include the contents within a parentheses? e.g. "uio" [ek3k 0die] 4229834 return "ek3k 0die"
write a code in python for evolutionary search method for multivarible
write a code in python for evolutionary search method for multivarible
code in python write a code where the initial value is compounded by a multiplier, rounded...
code in python write a code where the initial value is compounded by a multiplier, rounded to the nearest tenth Output: Initial Value: 10 Multiplier: 1.4 Number of compounds: 10 Your Values are: 10 , 14, 19.6 , 27.4, 38.4, 53.8, 75.3, 105.4, 147.6, 206.6
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT