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
4242500a
authored
Dec 11, 2017
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python code is added
parent
ce28b0b4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
homework2/main.py
homework2/main.py
0 → 100644
View file @
4242500a
def
input_number
(
text
):
n
=
input
(
text
)
try
:
float
(
n
)
except
ValueError
:
return
input_number
(
"The value you've just entered is the wrong type. Try again!
\n
"
)
return
float
(
n
)
def
read_array
(
n
):
tv
=
[]
for
counter
in
range
(
n
):
manufacture
=
input
(
"The manufacture is "
)
price
=
input_number
(
"And the price is "
)
tv
.
append
({
'manufacture'
:
manufacture
,
'price'
:
price
})
return
tv
def
read_discount
(
text
):
d
=
input_number
(
text
)
if
d
<
10
or
d
>
60
:
return
read_discount
(
"The discount can't be less than 10 or greater than 60. Try another
\n
"
)
return
d
def
set_discount
(
tv
,
d
):
for
counter
in
range
(
0
,
len
(
tv
)):
current
=
tv
[
counter
]
new_price
=
current
[
'price'
]
*
(
1.0
-
(
d
/
100.0
))
print
(
"d: "
,
d
,
"old price: "
,
current
[
'price'
])
tv
[
counter
][
'new_price'
]
=
new_price
return
tv
def
display
(
tv
):
print
(
'
%-16
s
%-12
s
%-12
s'
%
(
"Manufacture"
,
"Price"
,
"New price"
))
for
each
in
tv
:
print
(
'
%-16
s
%-12
f
%-12
f'
%
(
each
[
'manufacture'
],
each
[
'price'
],
each
[
'new_price'
]))
number
=
int
(
input_number
(
"Hey, how many TV sets do you want to compare?
\n
"
))
tv_sets
=
read_array
(
number
)
print
(
tv_sets
)
discount
=
read_discount
(
"Which discount do you want to get (in percents)?
\n
"
)
tv_sets
=
set_discount
(
tv_sets
,
discount
)
display
(
tv_sets
)
\ No newline at end of file
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