Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Project Work
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fabian Del Villar
Project Work
Commits
15a44127
Commit
15a44127
authored
1 year ago
by
Fabian
Browse files
Options
Downloads
Patches
Plain Diff
Create test2-11.py
parent
a69a33e1
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test2-11.py
+91
-0
91 additions, 0 deletions
test2-11.py
with
91 additions
and
0 deletions
test2-11.py
0 → 100644
+
91
−
0
View file @
15a44127
import
math
def
create_shape
():
svg_code
=
""
total_width
=
0
while
True
:
# Prompt for the shape
shape
=
input
(
"
Enter the shape (rectangle, circle, triangle):
"
)
if
shape
==
"
rectangle
"
:
shape_code
,
shape_width
=
create_rectangle
()
elif
shape
==
"
circle
"
:
shape_code
,
shape_width
=
create_circle
()
elif
shape
==
"
triangle
"
:
shape_code
,
shape_width
=
create_triangle
()
else
:
print
(
"
Invalid shape entered.
"
)
continue
# Add spacing between shapes
svg_code
+=
f
'
<rect x=
"
{
total_width
+
50
}
"
y=
"
0
"
width=
"
0
"
height=
"
0
"
/>
'
# Update the total width
total_width
+=
shape_width
+
50
# Append the shape code to the SVG code
svg_code
+=
shape_code
# Ask if the user wants to add another shape
add_another
=
input
(
"
Do you want to add another shape? (yes/no):
"
)
if
add_another
.
lower
()
!=
"
yes
"
:
break
# Write the SVG code to a file
with
open
(
'
shapes.svg
'
,
'
w
'
)
as
file
:
file
.
write
(
f
'
<svg xmlns=
"
http://www.w3.org/2000/svg
"
>
{
svg_code
}
</svg>
'
)
print
(
"
SVG file
'
shapes.svg
'
has been generated.
"
)
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
'
<rect x=
"
{
0
}
"
y=
"
{
0
}
"
width=
"
{
width
}
"
height=
"
{
height
}
"
fill=
"
none
"
stroke=
"
red
"
stroke-width=
"
0.05
"
/>
'
return
svg_code
,
width
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
'
<circle cx=
"
{
radius
}
"
cy=
"
{
radius
}
"
r=
"
{
radius
}
"
fill=
"
none
"
stroke=
"
red
"
stroke-width=
"
0.05
"
/>
'
return
svg_code
,
diameter
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
'
<polygon points=
"
0,0
{
side1
}
,0
{
side2
}
,
{
side3
}
"
fill=
"
none
"
stroke=
"
red
"
stroke-width=
"
0.05
"
/>
'
# Calculate the width of the triangle
triangle_width
=
max
(
side1
,
side2
,
side3
)
return
svg_code
,
triangle_width
create_shape
()
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment