dimanche 4 septembre 2016

Python: Summing Odd/Even Random Numbers Generates TypeError: 'int' object is not iterable

Yes, this question has been asked, but I cannot seem to apply the answers to my problem. There are several parts to this problem, and this is the biggest obstacle I've hit.

I need to generate a random list of 10 numbers between 10 & 90. From those random numbers I need to sum the totals of both the even and odd numbers.

def playlist():
nums = []
for nums in range(10):
    # Get random list of 10 numbers
    my_nums = random.randint(10, 90)
    print (my_nums,end=' ')
    even = []
    odd = []
    for x in my_nums:
        if x % 2 == 0:
            even.append[x]
            print(even)
        else:
            odd.append[x]
            print(odd)

When I run this, sometimes I get one or two numbers (usually the first two odd numbers), but mostly I get TypeError: 'int' object is not iterable.

Not gonna lie - my first language is PHP, not Python and that's becoming a huge problem for me :(

Any help is appreciated.




Aucun commentaire:

Enregistrer un commentaire