1

I wrote this simple code:

alpha=float(input('For the MC Test for the mean define alpha (0.10 and 0.05 only available at the moment): '))
if alpha!=0.05 or alpha!=0.10:
    while True:
        print('Please insert a value equal to 0.05 or 0.10')
        alpha=float(input('For the MC Test for the mean define alpha (0.10 and 0.05 only available at the moment): ')
else:
    print('MC test will control the FWER at exactly {}% (balanced test)'.format(alpha))

However it is creating a loop in which even when I type 0.05 it is asking again to insert alpha. I would appreciate your comments. Thanks.

Joshua Varghese
  • 5,082
  • 1
  • 13
  • 34
Al Ejandro
  • 45
  • 4

2 Answers2

1

Just rearrange the loops:

while True:
    if alpha not in [0.05,0.1]:
        print('Please insert a value equal to 0.05 or 0.10')
        alpha=float(input('For the MC Test for the mean define alpha (0.10 and 0.05 only available at the moment): '))
    else:
        print('MC test will control the FWER at exactly {}% (balanced test)'.format(alpha))
        break
Joshua Varghese
  • 5,082
  • 1
  • 13
  • 34
1

You can re-arrange your if statement to check the proper input first and in else statement and the code to read the data again and add a break statement once you get the proper input.

alpha=float(input('For the MC Test for the mean define alpha (0.10 and 0.05 only available at the moment): '))
if alpha==0.05 or alpha==0.10:
    print('MC test will control the FWER at exactly {}% (balanced test)'.format(alpha))
else:
    while True:
        print('Please insert a value equal to 0.05 or 0.10')
        alpha=float(input('For the MC Test for the mean define alpha (0.10 and 0.05 only available at the moment): ')
        if alpha==0.05 or alpha==0.10:
            print('MC test will control the FWER at exactly {}% (balanced test)'.format(alpha))
            break
Prudhvi
  • 1,095
  • 1
  • 7
  • 18