Reputation: 45
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.
Upvotes: 1
Views: 71
Reputation: 1115
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
Upvotes: 1
Reputation: 5202
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
Upvotes: 1