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