I have decided to learn python coming from a c++ background and i am trying to create a simple program to print odd numbers and calculate the sum of even numbers in a range given from the user.
while the code works correctly for some test cases my while loop checking if the first number is greater then the second number does not work as intended.
Here is the code:
number1= input("enter number 1: ") #line 5 error
number2= input("enter number 2: ")
number_list = []
while number1 >= number2:
number1= input("please enter a number: ")
number2= input("please enter a number larger than number 1: ")
for number in range(int(number1),int(number2)+1):
if number % 2 != 0:
print(number)
else:
number_list.append(number)
sum = sum(number_list)
print(f"the sum of all even numbers is {sum}")
for the given input (1,5) the output is correct ( 1,3,5) and sum is 6 but for any other input where the first number is not 1 i get stuck in a infinite loop from line 5.
with the input (2,10) -> infinite loop with the input (30,100) -> infinite loop until the input is a 1
not sure why it is not working as intended and think the logic is correct but maybe i am using c++ syntax?
EDIT: input (2,5) works correctly but (2,10) does not
any help would be appreciated