0

I would like to create a functin that determines if round.random(uniform(0,10)) is odd or even

I've tried this as many ways as I can but I'm one green banana import random def randmatch(x): if x == x%2 == 0: return even else: if x == x%2==1: return odd randmatch((round(random.uniform(0,10),2))) OUTPUT =========== RESTART: C:/Users/T/Desktop/Python 3.8/randmatch/rm001.py ========== >>> import random def randmatch(x): if x == x%2 == 0: print(even) else: if x == x%2==1: print(odd) randmatch((round(random.uniform(0,10),2))) OUTPUT =========== RESTART: C:/Users/T/Desktop/Python 3.8/randmatch/rm001.py ========== >>> import random def randmatch(x): x=round(random.uniform(0,10),2) if x == x%2 == 0: print(even) else: if x == x%2==1: print(odd) randmatch(x) OUTPUT =========== RESTART: C:/Users/T/Desktop/Python 3.8/randmatch/rm001.py ========== Traceback (most recent call last): File "C:/Users/T/Desktop/Python 3.8/randmatch/rm001.py", line 10, in <module> randmatch(x) NameError: name 'x' is not defined import random def randmatch(x): x=round(random.uniform(0,10),2) if x is x%2 == 0: print(even) else: if x is x%2=

15th Aug 2021, 7:59 PM
Aaron
Aaron - avatar
7 Respostas
+ 5
Put your code in a script on playground and check the indentation. Please tag the relevant programming language.
15th Aug 2021, 8:09 PM
Lisa
Lisa - avatar
+ 2
I'm not sure if this is what you want to do? https://code.sololearn.com/crf0Ry1sir3r/?ref=app Why do you round for 2 decimals? What did you try with x == x%2 == 0?
15th Aug 2021, 9:03 PM
Lisa
Lisa - avatar
0
done title ranflomat
15th Aug 2021, 8:41 PM
Aaron
Aaron - avatar
0
I round for two decimals because its pertenant for a math project i am working on. I dont want to say to much but floats to the second dec. Are important, and it has to be generated randomly
15th Aug 2021, 9:49 PM
Aaron
Aaron - avatar
0
Both thats the point. Im trying to encompass everything between .00 and 1000.00
15th Aug 2021, 10:16 PM
Aaron
Aaron - avatar
0
Im honestly going to have to carry most of this, but I appreciate your help, my education has to catch up to some of the concepts I'm researching.
15th Aug 2021, 10:21 PM
Aaron
Aaron - avatar
0
Awesome. Im brand new and view this as an opportunity to provide a better life for my family. So if I'm going to set a goal it might as well be monetized. All is duely noted. I appreciate the help.
15th Aug 2021, 10:48 PM
Aaron
Aaron - avatar