загружаю доработанное дз по джейсону без инам

This commit is contained in:
ehermakov 2023-10-01 23:22:53 +03:00
parent bca8f3814e
commit fe6cb7b8c1
5 changed files with 15 additions and 9 deletions

View File

@ -0,0 +1 @@
main.py

View File

@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" /> <excludeFolder url="file://$MODULE_DIR$/venv" />
</content> </content>
<orderEntry type="jdk" jdkName="Python 3.11 (13082023 ДЗ по фигурам JSON)" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.12 (13082023 ДЗ по фигурам JSON)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (13082023 ДЗ по фигурам JSON)" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (13082023 ДЗ по фигурам JSON)" project-jdk-type="Python SDK" />
</project> </project>

View File

@ -31,19 +31,24 @@ def create_shape(json):
def generate_shape(): def generate_shape():
max_length = 100
types = ['square', 'circle', 'rectangle'] types = ['square', 'circle', 'rectangle']
rnd = random.randint(0, len(types) - 1) colors = ['red', 'green', 'blue', 'yellow', 'black', 'white']
shape_type = types[rnd]
type_index = random.randint(0, len(types) - 1)
shape_type = types[type_index]
if shape_type == 'circle': if shape_type == 'circle':
obj = Circle(rnd) obj = Circle(random.randint(1, max_length))
elif shape_type == 'square': elif shape_type == 'square':
obj = Square(rnd) obj = Square(random.randint(1, max_length))
elif shape_type == 'rectangle': elif shape_type == 'rectangle':
obj = Rectangle(rnd, rnd) obj = Rectangle(random.randint(1, 100), random.randint(1, max_length))
else: else:
raise TypeError(f'Происходит что-то непонятное') raise TypeError(f'Происходит что-то непонятное')
obj.color = 'unknown'
return obj color_index = random.randint(0, len(colors) - 1)
obj.color = colors[color_index]
def json_to_python(filename): def json_to_python(filename):