To use the functions of the methods floor
and ceil
, you have to first import the methods.
Another thing, when we work with funções
we should know how implementa-las
.
Note below the solution of the question...
from math import floor, ceil
def arrend(num2):
if num2 - floor(num2) < 0.5:
return floor(num2)
return ceil(num2)
num = float(input("digite um número não inteiro: "))
print("o número inteiro correspondente é: {}".format(arrend(num)))
Note that when we execute this code we receive the message: Digite um número não inteiro:
. Right now we must enter a real number and press enter
. At this point the value captured by the input is passed as a parameter to the function arrend()
. Getting there, the block if
will check whether n - floor(num2) < 0.5
. If the check is positive the return of the function will be floor(num2)
. Otherwise, the function return will be ceil(num2)
.
hi @Vinicius Macelai it only worked for Math.floor but it didn’t work for Math.Ceil
– Márcio Feitosa
@Márciofeitosa it returns only once, so it only does the number Return command, to return the two values, look at my new answer.
– Vinicius Macelai
It keeps not returning anything to Ceil and now when the number should go to floor it returns both (floor and Ceil)
– Márcio Feitosa
Ah, I understood your problem, you wanted if it failed the if condition, return to Ceil, edited again,
– Vinicius Macelai
You were the guy in that...
– Márcio Feitosa