Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Graphics and File handling

Course- BTech Type- Core


Course Code- CSET101 Course Name- Computational Thinking
and Programming
Year- 2023 Semester- odd
Date- Batch- ALL

Tutorial Assignment 12 Solutions

Tutorial title: Graphics, File handling and Miscellaneous

CO Mapping

Name CO1 CO2 CO3


Loops, Sequence Operations   

1.
import turtle

# Function to draw an equilateral triangle


def draw_equilateral_triangle(side_length):
for _ in range(3):
turtle.forward(side_length)
turtle.left(120)

# Set up the turtle


turtle.speed(1) # You can adjust the speed if needed
turtle.pensize(2)

# Specify the side length of the equilateral triangle


side_length = 100

# Draw the equilateral triangle


draw_equilateral_triangle(side_length)

# Keep the window open until it is manually closed


turtle.done()

2.
def display_file_characters(file_path):
try:
with open(file_path, 'r') as file:
# Read the content of the file
content = file.read()

# Extract characters from the 10th to the 30th position


start_position = 9 # 0-based indexing, so 10th character is at index 9
end_position = 29 # 30th character is at index 29

selected_characters = content[start_position:end_position+1]

# Display the selected characters


print(f"Characters from the 10th to 30th position: {selected_characters}")
except FileNotFoundError:
print(f"File not found: {file_path}")
Graphics and File handling
except Exception as e:
print(f"An error occurred: {e}")

# Specify the path to your file


file_path = 'F:\Bennett classes\Group 5\sample.txt'

# Call the function to display characters


display_file_characters(file_path)

3.
New Delhi is the capital of India.
Hindi is the most widely spoken language of India.
India is a developing country.
Washington, D.C. is the capital of USA.
English is the primary language of USA.
USA is a developed country.

4. Cow gives us milk


Cow lives in a farm
Horse lives in a farm

5. The euler number is 2.718


The golden ratio is 1.618
The pi number is 3.142371
True
AttributeError: 'SpecialNumbers' object has no attribute 'msg'

6.
This is student class
{'name': 'Amit', 'id': 101, 'age': 22}
__main__

7. Answer: b
Explanation: The output of the code shown above will be a single square. This is because the
function t.penup() is used to lift the pen after the construction of the first square. However, the
function t.pendown() has not been used to put the pen back down. Hence, the output shape of this
code is one square, of side 100 units.

8. d) Star

9. b) False
Explanation: In the code shown above, we have used the function t.penup() to life the pen
from the canvas. However, we have not used the function t.pendown() to keep the pen back
down. The function turtle.isdown() returns True if the pen is down and False if the pen is not
down. Hence the output is False.
Graphics and File handling
10.A. c) East
B. a)position()

Explanation: The functions fillcolor(), goto() and setheading() accept arguments, whereas the
function position() does not accept any arguments. The function position() returns the current
position of the turtle.

11.
Answer: b

You might also like