Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a3dc1170
authored
Oct 01, 2017
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
3b50aa06
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
lab4/task2.py
lab4/task2.py
0 → 100644
View file @
a3dc1170
import
random
stores
=
[
None
]
*
3
stores_name
=
[
'Happy Lime'
,
'Unreleased'
,
'Kristina'
]
for
num
in
range
(
0
,
len
(
stores_name
)):
print
(
'
\n
Fill '
+
stores_name
[
num
]
+
' store'
)
items
=
[]
print
(
"Enter the item's name, the price will be generated automatically"
)
for
x
in
range
(
0
,
5
):
item_name
=
input
()
item
=
{
'item_name'
:
item_name
,
'item_price'
:
random
.
randrange
(
1
,
20
)}
items
.
append
(
item
)
store
=
{
'store_name'
:
stores_name
[
num
],
'items'
:
items
}
stores
[
num
]
=
store
cheap_items
=
[]
for
x
in
range
(
0
,
len
(
stores
)):
for
y
in
range
(
0
,
5
):
if
stores
[
x
][
'items'
][
y
][
'item_price'
]
<
10
:
item
=
stores
[
x
][
'items'
][
y
]
cheap_item
=
{
'price'
:
item
[
'item_price'
],
'name'
:
item
[
'item_name'
],
'store'
:
stores
[
x
][
'store_name'
]}
cheap_items
.
append
(
cheap_item
)
for
i
in
range
(
1
,
len
(
cheap_items
)):
j
=
i
-
1
key
=
cheap_items
[
i
][
'price'
]
while
(
cheap_items
[
j
][
'price'
]
>
key
)
and
(
j
>=
0
):
cheap_items
[
j
+
1
][
'price'
]
=
cheap_items
[
j
][
'price'
]
cheap_items
[
j
+
1
][
'name'
]
=
cheap_items
[
j
][
'name'
]
cheap_items
[
j
+
1
][
'store'
]
=
cheap_items
[
j
][
'store'
]
j
-=
1
cheap_items
[
j
+
1
][
'price'
]
=
key
for
m
in
range
(
0
,
len
(
cheap_items
)):
print
(
cheap_items
[
m
][
'name'
]
+
' from '
+
cheap_items
[
m
][
'store'
]
+
' store costs '
+
str
(
cheap_items
[
m
][
'price'
])
+
' euros'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment