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
2c4ea41b
authored
Oct 13, 2017
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Done >_<
parent
08dc9064
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
homework1/main.py
homework1/report.pdf
homework1/main.py
0 → 100644
View file @
2c4ea41b
import
math
def
input_float
(
text
):
# check if the input can be converted to float to prevent errors
inp
=
input
(
text
)
try
:
float
(
inp
)
except
ValueError
:
return
input_float
(
text
)
return
float
(
inp
)
def
input_with_conditions
(
text
,
operator
):
# check if the input fits the conditions listed in the task, i.e.
# H > 0, C >=1
# since we'll need to divide by A I also added A != 0 to prevent the errors
error_msg
=
"The value doesn't fit the conditions, try again "
value
=
input_float
(
text
)
if
(
operator
==
'>'
and
value
<=
0
)
or
(
operator
==
'>='
and
value
<
1
)
or
(
operator
==
'!='
and
value
==
0
):
return
input_with_conditions
(
error_msg
,
operator
)
return
value
def
calculate_x
(
until
):
# calculate x in the necessary points
xx
=
a
+
h
for
i
in
range
(
1
,
until
+
1
):
xx
=
xx
+
h
*
math
.
pow
(
c
,
i
)
return
round
(
xx
,
3
)
def
calculate_y
(
xx
):
# calculate y according to the formula and return the (x, y) function in an array
yy
=
float
(
math
.
pow
(
xx
,
2
)
+
20
*
xx
-
14
)
/
math
.
sqrt
(
xx
)
-
(
1
+
xx
)
/
xx
return
round
(
yy
,
3
)
def
print_table
():
# print the data in a table
titles
=
[
'x'
,
'y'
]
data
=
[
titles
]
+
list
(
zip
(
x
,
y
))
for
i
,
d
in
enumerate
(
data
):
line
=
'|'
.
join
(
str
(
x
)
.
ljust
(
12
)
for
x
in
d
)
print
(
line
)
if
i
==
0
:
print
(
'-'
*
len
(
line
))
# input all the values: A, H, C, YM
a
=
input_with_conditions
(
"Enter a starting value A = "
,
'!='
)
h
=
input_with_conditions
(
"Enter a step H = "
,
'>'
)
c
=
input_with_conditions
(
"Enter the step's coefficient C = "
,
'>='
)
ym
=
input_float
(
"Enter function value upper limit YM = "
)
x
=
[]
y
=
[]
x
.
append
(
round
(
a
,
3
))
y
.
append
(
calculate_y
(
a
))
x
.
append
(
round
(
a
+
h
,
3
))
y
.
append
(
calculate_y
(
a
+
h
))
counter
=
1
while
counter
<
14
:
x
.
append
(
calculate_x
(
counter
))
y
.
append
(
calculate_y
(
calculate_x
(
counter
)))
counter
+=
1
if
not
y
[
len
(
y
)
-
1
]
<=
ym
:
y
.
remove
(
y
[
len
(
y
)
-
1
])
break
print_table
()
homework1/report.pdf
0 → 100644
View file @
2c4ea41b
File added
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