Skip to content
Snippets Groups Projects
Commit b9be0464 authored by Fabian's avatar Fabian
Browse files

Create test2-6.py

parent 655ea45d
No related merge requests found
import math
def create_shape():
# Prompt for the shape
shape = input("Enter the shape (rectangle, circle, triangle): ")
if shape == "rectangle":
create_rectangle()
elif shape == "circle":
create_circle()
elif shape == "triangle":
create_triangle()
else:
print("Invalid shape entered.")
def create_rectangle():
# Prompt for the length and width of the rectangle
width = float(input("Enter the width of the rectangle: "))
height = float(input("Enter the height of the rectangle: "))
# Create the SVG code for the rectangle
svg_code = f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}">'
svg_code += f'<rect x="0" y="0" width="{width}" height="{height}" fill="none" stroke="red" stroke-width="0.05" />'
svg_code += '</svg>'
# Write the SVG code to a file
with open('rectangle.svg', 'w') as file:
file.write(svg_code)
print("Rectangle SVG file 'rectangle.svg' has been generated.")
def create_circle():
# Prompt for the radius of the circle
radius = float(input("Enter the radius of the circle: "))
# Calculate the diameter
diameter = 2 * radius
# Create the SVG code for the circle
svg_code = f'<svg xmlns="http://www.w3.org/2000/svg" width="{diameter}" height="{diameter}">'
svg_code += f'<circle cx="{radius}" cy="{radius}" r="{radius}" fill="none" stroke="red" stroke-width="0.05" />'
svg_code += '</svg>'
# Write the SVG code to a file
with open('circle.svg', 'w') as file:
file.write(svg_code)
print("Circle SVG file 'circle.svg' has been generated.")
def create_triangle():
# Prompt for the lengths of the triangle's sides
side1 = float(input("Enter the length of the first side of the triangle: "))
side2 = float(input("Enter the length of the second side of the triangle: "))
while True:
side3 = float(input("Enter the length of the third side of the triangle: "))
if side1 + side2 > side3 and side2 + side3 > side1 and side1 + side3 > side2:
break
else:
print("The given side lengths do not satisfy the triangle inequality theorem.")
if side1 + side2 <= side3:
print("The third side length must be smaller.")
elif side2 + side3 <= side1:
print("The first side length must be smaller.")
elif side1 + side3 <= side2:
print("The second side length must be smaller.")
# Create the SVG code for the triangle
svg_code = f'<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">'
svg_code += f'<polygon points="0,0 {side1},0 {side2},{side3}" fill="none" stroke="red" stroke-width="0.05" />'
svg_code += '</svg>'
# Write the SVG code to a file
with open('triangle.svg', 'w') as file:
file.write(svg_code)
print("Triangle SVG file 'triangle.svg' has been generated.")
create_shape()
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment