Feb-24-2022, 05:15 AM
Hello! first post here, and it's my first time using Python. I was given a task about creating a console program in Python that allows to accept only 10 integers on a list. Upon entering integers on the list, it will not accept 3 consecutive odd integers. Example, the user entered 4, 8, 5, 3, 6, 1, 3, 5, the eighth integer will not be accepted because it is the third odd integer added on the list consecutively. The user may now continue to enter again on the eighth integer: 8, 3, and 7. The entered integers are: 4, 8, 5, 3, 6, 1, 3, 8, 3 and 7.
I'm still confused cause it still wasn't clarified in our lessons but I was able to make a reference code to be able to count even and odd numbers (I know it's a different thing) but how am I able to prompt an error or an invalid message if the input is an odd number
here's the code I made as a reference:
I'm still confused cause it still wasn't clarified in our lessons but I was able to make a reference code to be able to count even and odd numbers (I know it's a different thing) but how am I able to prompt an error or an invalid message if the input is an odd number
here's the code I made as a reference:
num1 = int(input("Enter an Integer:")) num2 = int (input("Enter an Integer:")) num3 = int (input("Enter an Integer:")) num4 = int (input("Enter an Integer:")) num5 = int (input("Enter an Integer:")) num6 = int (input("Enter an Integer:")) num7 = int (input("Enter an Integer:")) num8 = int (input("Enter an Integer:")) num9 = int (input("Enter an Integer:")) num10 = int (input("Enter an Integer:")) even_count, odd_count = 0, 0 for num in num1,num2,num3,num4,num5,num6,num7,num8,num9,num10: if num % 2 == 0: even_count += 1 else: odd_count += 1 print("Even numbers on the list", even_count) print("Odd numbers on the list", odd_count)would be really grateful for any help, thanks!