Python Forum
Program that allows to accept only 10 integers but loops if an odd number was entered
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program that allows to accept only 10 integers but loops if an odd number was entered
#1
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:

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!
Reply


Messages In This Thread
Program that allows to accept only 10 integers but loops if an odd number was entered - by gachicardo - Feb-24-2022, 05:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Program to check whether a number is palindrome or not PythonBoy 18 3,346 Sep-12-2023, 09:27 AM
Last Post: PythonBoy
  Help needed for a program using loops PythonBoy 5 1,595 Sep-10-2023, 06:51 AM
Last Post: PythonBoy
  Python Program to Find the Factorial of a Number elisahill 2 1,598 Nov-21-2022, 02:25 PM
Last Post: DeaD_EyE
  I will accept any help with this task (compression code) Malin3k 3 2,432 Feb-10-2021, 10:20 AM
Last Post: Larz60+
  How can details be dynamically entered into a list and displayed using a dictionary? Pranav 5 3,112 Mar-02-2020, 10:17 AM
Last Post: buran
  How to collect all integers with minimum number of rounds? meknowsnothing 6 3,515 Jun-11-2019, 08:36 PM
Last Post: jefsummers
  MyProgrammingLab wont accept anything I put in chicks4 2 11,737 Feb-10-2019, 11:44 PM
Last Post: chicks4
  Program that displays the number with the greatest amount of factors ilusmd 3 2,959 Nov-01-2018, 08:28 PM
Last Post: ichabod801
  Program to print: Last Name, ID, Mobile Number, All panick1992 14 10,223 Mar-15-2017, 02:46 PM
Last Post: panick1992

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020