if Else in assigning a Python variable

Asked

Viewed 7 times

0

I want to understand that "ma" assignment on line 6 and "me" on line 7. I don’t even have a focus on understanding what the code does, I just want to understand this attribution with if I hadn’t seen it yet. If anyone can explain what that would be and if it’s strictly necessary it would help me.

Thank you guys so much.


n = int(input("Digite N: "))
ma = None
me = None
for i in range(n):
   x = float(input("Digite um número: "))
   ma = ma if ma != None and ma >  x else x
   me = me if me != None and me < x else x

print ('O maior valor digitado foi {} e o menor foi {}'.format(ma,me))

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.