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
cf63888d
authored
Oct 16, 2017
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
catched some errors
parent
2c4ea41b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
11 deletions
homework1/main.py
homework1/main.py
View file @
cf63888d
...
@@ -7,7 +7,13 @@ def input_float(text):
...
@@ -7,7 +7,13 @@ def input_float(text):
try
:
try
:
float
(
inp
)
float
(
inp
)
except
ValueError
:
except
ValueError
:
return
input_float
(
text
)
try
:
complex
(
inp
)
except
:
return
input_float
(
"It's not a number, try again: "
)
return
input_float
(
"It seems that you're trying to enter a complex number, unfortunately we don't support them. "
"Try again: "
)
return
float
(
inp
)
return
float
(
inp
)
...
@@ -17,7 +23,11 @@ def input_with_conditions(text, operator):
...
@@ -17,7 +23,11 @@ def input_with_conditions(text, operator):
# since we'll need to divide by A I also added A != 0 to prevent the errors
# 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 "
error_msg
=
"The value doesn't fit the conditions, try again "
value
=
input_float
(
text
)
value
=
input_float
(
text
)
if
(
operator
==
'>'
and
value
<=
0
)
or
(
operator
==
'>='
and
value
<
1
)
or
(
operator
==
'!='
and
value
==
0
):
if
(
operator
==
'>'
and
value
<=
0
)
or
(
operator
==
'>='
and
value
<
1
):
return
input_with_conditions
(
error_msg
,
operator
)
elif
operator
==
'!='
and
value
<=
0
:
error_msg
=
"Hey, sorry, we'll have to divide by A and get the square root of it, so all of the values less "
\
"or equal to 0 are unacceptable "
return
input_with_conditions
(
error_msg
,
operator
)
return
input_with_conditions
(
error_msg
,
operator
)
return
value
return
value
...
@@ -25,8 +35,8 @@ def input_with_conditions(text, operator):
...
@@ -25,8 +35,8 @@ def input_with_conditions(text, operator):
def
calculate_x
(
until
):
def
calculate_x
(
until
):
# calculate x in the necessary points
# calculate x in the necessary points
xx
=
a
+
h
xx
=
a
+
h
for
i
in
range
(
1
,
until
+
1
):
for
i
in
range
(
1
,
until
+
1
):
xx
=
xx
+
h
*
math
.
pow
(
c
,
i
)
xx
=
xx
+
h
*
math
.
pow
(
c
,
i
)
return
round
(
xx
,
3
)
return
round
(
xx
,
3
)
...
@@ -53,20 +63,21 @@ h = input_with_conditions("Enter a step H = ", '>')
...
@@ -53,20 +63,21 @@ h = input_with_conditions("Enter a step H = ", '>')
c
=
input_with_conditions
(
"Enter the step's coefficient C = "
,
'>='
)
c
=
input_with_conditions
(
"Enter the step's coefficient C = "
,
'>='
)
ym
=
input_float
(
"Enter function value upper limit YM = "
)
ym
=
input_float
(
"Enter function value upper limit YM = "
)
x
=
[]
x
=
[]
y
=
[]
y
=
[]
x
.
append
(
round
(
a
,
3
))
if
calculate_y
(
a
)
<=
ym
:
y
.
append
(
calculate_y
(
a
))
x
.
append
(
round
(
a
,
3
))
x
.
append
(
round
(
a
+
h
,
3
))
y
.
append
(
calculate_y
(
a
))
y
.
append
(
calculate_y
(
a
+
h
))
if
calculate_y
(
a
+
h
)
<=
ym
:
x
.
append
(
round
(
a
+
h
,
3
))
y
.
append
(
calculate_y
(
a
+
h
))
counter
=
1
counter
=
1
while
counter
<
14
:
while
counter
<
14
:
x
.
append
(
calculate_x
(
counter
))
x
.
append
(
calculate_x
(
counter
))
y
.
append
(
calculate_y
(
calculate_x
(
counter
)))
y
.
append
(
calculate_y
(
calculate_x
(
counter
)))
counter
+=
1
counter
+=
1
if
not
y
[
len
(
y
)
-
1
]
<=
ym
:
if
not
y
[
len
(
y
)
-
1
]
<=
ym
:
y
.
remove
(
y
[
len
(
y
)
-
1
])
y
.
remove
(
y
[
len
(
y
)
-
1
])
break
break
print_table
()
print_table
()
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