Reputation: 11
I am a new coder, sorry if my question is bad or I am not following proper etiquette!
I am designing a basic program that rolls dice. It is supposed to roll dice until the total points of either the computer or the user equals 100. However, even though my point totaler is working, the loop won't end. Anyone know why this is? Thank you!
def main():
GAME_END_POINTS = 100
COMPUTER_HOLD = 10
is_user_turn = True
user_pt = 0
computer_pt = 0
welcome()
while computer_pt < GAME_END_POINTS or user_pt < GAME_END_POINTS:
print_current_player(is_user_turn)
if is_user_turn is True:
user_pt = user_pt + take_turn(is_user_turn, COMPUTER_HOLD)
elif is_user_turn is False:
computer_pt = computer_pt + take_turn(is_user_turn, COMPUTER_HOLD)
report_points(user_pt, computer_pt)
is_user_turn = get_next_player(is_user_turn)
Upvotes: 0
Views: 72
Reputation: 1
you can print computer_pt and user_pt in the loop to see what happened in this two variable, then you will find the answer by your self. Print variable in loop is a common way to debug your code.
Upvotes: 0
Reputation: 1932
You while loop will only end if both computer_pt >= GAME_END_POINTS and user_pt >= GAME_END_POINTS
. Are you sure that those two variables satisfy those two conditions?
Upvotes: 0
Reputation: 87134
The condition is always True
because either the computer or the user will have a points total less than 100.
Instead of or
use and
:
while computer_pt < GAME_END_POINTS and user_pt < GAME_END_POINTS:
Now the loop will continue only when both the user and the computer have a points total less than 100. As soon as one of them has more than 100 the condition will be be False
and the loop will terminate.
Upvotes: 2