dimanche 26 mai 2019

Problem with variables inside Nested Ifs inside While Loop

When i run the code it runs well till the 3rd "If" in the "num_dozen" section. From that part it does not append the varibles to the list! I note it that it only prints the "else" statement!

I have tried changing the "else" statements to "elif" but it does not work.

BTW i am a starting with python.

Here is the code:

while True:
var = input("Ingrese Numero: ")
if var == "exit": break
num = int(var)
if num == 0:
    num_column = "Zero"
elif (num + 2) % 3 == 0:
    num_column = "1stC"
elif (num + 1) % 3 == 0:
    num_column = "2ndC"
else:
    num_column = "3rdC"
column_list.append(num_column)

if num == 0:
    num_even_odd = "Zero"
elif num % 2 == 0:
    num_even_odd = "Even"
else:
    num_even_odd = "Odd"
even_odd_list.append(num_even_odd)

if num == 0:
    num_dozen = "Zero"
elif num <= 12:
    num_dozen = "1stD"
elif num > 12 and num <= 24:
    num_dozen = "2ndD"
else:
    num_dozen = "3rdD"
    dozen_list.append(num_dozen)

if num == 0:
    num_color = "Zero"
elif num in red_number_list:
    num_color = "Red"
else:
    num_color = "Black"
    color_list.append(num_color)

if num in tier_number_list:
    num_french = "Tier"
elif num in orphelins_number_list:
    num_french = "Orphelins"
else:
    num_french = "Voisins"
    french_list.append(num_french)

if num == 0:
    num_half = "Zero"
elif num <= 18:
    num_half = "1to18"
else:
    num_half = "19to36"
    half_list.append(num_half)
    continue

I excpect that when i print the "lists" it contains all the numbers. Beacuse the code only prints this:

Ingrese Numero: 3
Ingrese Numero: 0
Ingrese Numero: 21
Ingrese Numero: 36
Ingrese Numero: 14
Ingrese Numero: 8
Ingrese Numero: exit


    Goodbye! Fella!
Half: 
['19to36', '19to36']
French: 
['Voisins', 'Voisins', 'Voisins']
Color: 
['Black']
Dozen: 
['3rdD']
Column: 
['3rdC', 'Zero', '3rdC', '3rdC', '2ndC', '2ndC']
E/O: 
['Odd', 'Zero', 'Odd', 'Even', 'Even', 'Even']

Every list should be the same "len".

If anyone could tell me what am i doing wrong i would really appretiate it! Thanks! And i wish u have a great week!

Aucun commentaire:

Enregistrer un commentaire