We will solve your problem step by step.
First, let’s see the use of range
. Let’s look at the documentation and... For life, it only accepts integer numbers! This function accepts up to 3 parameters (check that answer for more chewed details). How we will proceed then?
An alternative is to proceed arithmetically. If we want to take the values between m
and M
leaping from 0.5
in 0.5
(being i
iterator), this is identical to picking the values between 2*m
and 2*M
leaping from 1
in 1
, iterating on the variable i_dobro
which can easily be transformed into i = i_dobro/2
. But this only works in Python 3 (for Python 2 you have to divide by 2.0
) and if m
and M
be whole...
So maybe we can use while
? Let’s start with m
, as small as M
, increasing 0.5
every step... it seems, it seems reasonable.
Now, how about we find out who it is m
and M
that I so much quoted above? Well, m
is the lower margin of the range, while M
is the upper margin. As this data is read from the standard entry, and has no restriction or complementary text to this problem, I can only believe that the two entries will be numbers possibly out of order. Then let’s go n1
to the first number and n2
for the second number. To determine m
and M
that’s how it is:
(M, m) = (n1, n2) if n1 > n2 else (n2, n1)
Okay, so generally our iteration goes like this (I’ll keep your reading as much as I disagree with it):
n1 = eval(input())
n2 = eval(input())
(M, m) = (n1, n2) if n1 > n2 else (n2, n1)
i = m
while i < M:
# ação interessante da iteração
i += 0.5
So, how to make the action interesting of iteration? The desired result is the impression of the evaluation of the polynomial before the i
past. I see the following options:
- calculate directly in the
print
- define a priori function and call it cheerfully
- create a lambda and call it even more cheerfully
For the first option, it is only necessary to change the commented section:
print(3* i**3 -5*i + 0.8)
For the second option, before taking the proper readings, set the function like this:
def polinomio(x):
return 3* x**3 -5*x + 0.8
Then call inside the print
:
print(polinomio(i))
For lambda alternative, before iteration, create lambda function and assign to variable polinomio
:
polinomio = (lambda x: 3* x**3 -5*x + 0.8)
And call inside the print
as if it were a traditional function:
print(polinomio(i))
You really want something that varies between
[x,x)
varying from0.5
?– Jefferson Quesado
See here how to use the
range
: https://answall.com/a/204411/64969– Jefferson Quesado
But they’re two different values. For example, if the program reads the values 2.4 and 4.6, it should print the value of that polynomial for the following points (values of x): 2.4, 2.9, 3.4, 3.9 and 4.4.
– RiceGum
range starting at the lower end and spaced 0.5
– RiceGum
You expect the interpreter to know which is the first
x
and what the secondx
? For him it’s allx
, then you have lost any and all reference to the first information read. Not to mention what you callpolinomio
is not a polynomial, but a real number obtained by calculating a polynomial forx
worth its second value– Jefferson Quesado
You can give me a suggestion then pff how to enter another value for x and resolve for those values spaced between 0.5?
– RiceGum
Am I a novice in python and would like an answer to my mistake or suggestion? Thank you.
– RiceGum