Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python program way to check for type in Python?

def main():
    a,b=numbers(5,1,100)
print("Number of Odd values = " + str(a))
print("Number of Even values = " + str(b))
def numbers(N,A,B):
    even_count,odd_count=0,0
    for i in range(N):
        n=random.randint(A,B)        
        if n%2==0:
            even_count+=1
        else:
            odd_count+=1
    return odd_count, even_count
main()

Need fix this code.i don’t know when the number can’t go through.
print("Number of Odd values = " + str(a))
NameError: name ‘a’ is not defined

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try this:

import random

def numbers(N,A,B):
    even_count,odd_count=0,0
    for i in range(N):
        n=random.randint(A,B)        
        if n%2==0:
            even_count+=1
        else:
            odd_count+=1
    return odd_count, even_count
    
a,b=numbers(5,1,100) 

print("Number of Odd values = " + str(a))
print("Number of Even values = " + str(b))

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading