jeudi 28 février 2019

Creating a function with a condition in Python

I need to create a function named 'Bernoulli' that should take 2 input variables 'rr' and 'p' and should return a value of 1 if rr is less than or equal to p and a value of 0 if rr is greater than p.

The code I have produced so far is this:

rr=float(input())
p=float(input())
def bernoulli(rr,p):
  if rr<=p:
    return 'X=1'
  else:
    return 'X=0'

I am not sure how correct this is.

Upon running tests I get this feedback: Your program took too long to execute. Make sure that it isn't waiting for input and that there is no infinite loop.

Aucun commentaire:

Enregistrer un commentaire