 Poker Dice while loop - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Poker Dice while loop (/thread-3492.html) Poker Dice while loop - gullidog - May-28-2017 I am not sure why my while loop is broken, any help would be greatly appreciated. ```#This program will simulate a poker dice game. import random import time def isEven(number): if (number % 2 == 0): return True else: return False def isOdd(number): if (number % 2 == 1): return True else: return False pts = 0 a = 0 print("---Poker Dice---\nWelcome User! This is Poker Dice, three dice will be thrown and score points:\nThree of a Kind = +50 pts, Straight = +30 pts, Three Odd Numbers = +15 pts,\nThree Even Numbers = +15 pts, One Pair = +10 pts.") while a == 0: d1 = random.randint(1,6) d2 = random.randint(1,6) d3 = random.randint(1,6) print("The first die rolled", d1) print("The second die rolled",d2) print("The third die rolled",d3) if d1 == d2 and d1 == d3: print("All three dice match which means +50 pts!") pts += 50 if d1==(d2+1) and d1==d3+2: pts += 30 print("Wow, you just rolled a straight which means +30 pts!") elif d1==(d3+1) and d1==d2+2: pts += 30 print("Wow, you just rolled a straight which means +30 pts!") elif d2==(d3+1) and d2==d1+2: pts += 30 print("Wow, you just rolled a straight which means +30 pts!") elif d2==(d1+1) and d2==d3+2: pts += 30 print("Wow, you just rolled a straight which means +30 pts!") elif d3==(d1+1) and d3==d2+2: pts += 30 print("Wow, you just rolled a straight which means +30 pts!") elif d3==(d2+1) and d3==d1+2: pts += 30 print("Wow, you just rolled a straight which means +30 pts!") if isEven(d1) and isEven(d2) and isEven(d3): pts += 15 print("You just rolled three even numbers! Which means +15 pts!") if isOdd(d1) and isOdd(d2) and isOdd(d3): pts += 15 print("You just rolled three odd numbers! Which means +15 pts!") if d1 == d2 or d1 == d3 or d2 == d1 or d2 == d3 or d3 == d1 or d3 == d2: pts += 10 print("Two of the dice match, which means +10 pts!") print("Overall you scored", pts,"points!") fa = input("Would you like to re-roll your dice? Type 'yes' to re-roll or type 'no' to go home safe with your current points.\n").lower() if fa == 'yes' or 'y': print("Wow, you are brave!") pts = 0 else: print("Fine then, we hope to see you again soon! Goodbye.") a += 1 time.sleep(3) quit() ``` RE: Poker Dice while loop - ichabod801 - May-28-2017 This is your error: `if fa == 'yes' or 'y':`Python reads it like this: `if (fa == 'yes') or ('y'):`Since any non-empty string evaluates as True, the second part is True, and the whole expression is always True. You want: `if fa == 'yes' or fa == 'y':`or `if fa in ('yes', 'y'):`I would also use break instead of quit, and more descriptive variable names (a and fa are confusing). Also, if you put the three dice into a list, and then sort that list, then the comparisons are much easier (especially for straights). RE: Poker Dice while loop - gullidog - May-28-2017 (May-28-2017, 08:03 PM)ichabod801 Wrote: This is your error: ` if fa == 'yes' or 'y': ` Python reads it like this: ` if (fa == 'yes') or ('y'): ` Since any non-empty string evaluates as True, the second part is True, and the whole expression is always True. You want: ` if fa == 'yes' or fa == 'y': ` or ` if fa in ('yes', 'y'): ` I would also use break instead of quit, and more descriptive variable names (a and fa are confusing). Also, if you put the three dice into a list, and then sort that list, then the comparisons are much easier (especially for straights).Thank You!