0

enter image description here

i want to use function in simple prigram but it`s giving me wrong result in a wrong way

i wanna make a loop with function and ask as many time i want to see if the number i enterd is odd or even

def new_game():
game()


def game():
    a = int(input("please enter the number... "))
    if a % 2 == 0:
        print(a, " Is even ")
    else:
        print(a, " Is odd ")


game()


def check():
    ask = input("Do you want to continue ? yes/no  ").lower()
    if ask == 'yes':
       return True
    elif ask == 'no':
        exit()
    else:
        print('Bye')


while check():
    game()
    check()
    break

1 Answers1

1

You actually had it. But the break in your while loop is not needed and is what is causing your problem. Say you entered y, it will exit check() and break. Remove that.

while check():
    game()
    check()
    #break is gone

full code




def game():
    a = int(input("please enter the number... "))
    if a % 2 == 0:
        print(a, " Is even ")
    else:
        print(a, " Is odd ")




def check():
    ask = input("Do you want to continue ? yes/no  ").lower()
    if ask == 'yes':
       return True
    elif ask == 'no':
        exit()
    else:
        print('Bye')

game()
while check():
    game()
    check()
    
Buddy Bob
  • 5,829
  • 1
  • 13
  • 44