Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple cards game
#4
Stared at this code for way too long before I saw the problem.
suma is set to 0 before entering the while loop. if the first iteration produces "two of hearts", "six of spades", "four of diamonds", "ace of spades", "jack of clubs", then suma will be 1 and the if clause will pass.
Now what happens on the second iteration? suppose the choices are "three of spades", "ten of hearts", "king of spades", "four of clubs", "nine of diamonds". Well, suma is still 1 from the previous iteration, so even though nothing is added, it will still be 1 in the if clause and it will pass again.

The solution? Put suma = 0 within the while loop, not outside of it.
Reply


Messages In This Thread
Simple cards game - by blackpanda - Mar-26-2020, 09:47 AM
RE: Simple cards game - by newyawksupreme - Apr-02-2020, 05:02 PM
RE: Simple cards game - by micseydel - Apr-10-2020, 06:47 PM
RE: Simple cards game - by TomToad - Apr-10-2020, 08:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Classes, OOP, building deck of 52 playing cards Drone4four 9 3,927 Jan-19-2022, 02:53 PM
Last Post: Drone4four
  Generating random business cards Inkanus 2 2,214 Dec-08-2020, 09:41 PM
Last Post: buran
  python program on cards marc237 3 2,775 Apr-27-2019, 09:26 PM
Last Post: ichabod801
  Need help with simple guessing game! ghost0fkarma 2 2,821 Nov-03-2018, 01:19 AM
Last Post: ghost0fkarma
  Easy equipment system for simple game and problems with it naisyrk 3 3,319 Sep-01-2018, 10:05 AM
Last Post: Gribouillis
  Errors in simple text adventure game? ecloev 5 4,883 Apr-10-2018, 05:55 PM
Last Post: nilamo
  Simple Hangman Game Issue andrew95 2 4,365 Apr-02-2018, 02:24 PM
Last Post: andrew95
  Trouble with simple roulette game chadandersen1 9 7,820 Oct-21-2017, 02:22 AM
Last Post: chadandersen1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020