[Solved] Card Game with Python, Java

Card Game: The Westland Game Fair is the premier event of its kind for kids interested in some intellectual and cognitive brain games. Alan, a middle school boy is visiting the fair where he is very much drawn by the Card game.

The game’s rules are:
A player needs to pick 3 cards from a big lot of cards. There are 4 types of Cards namely Spade(S), Heart(H), Club(C) and Diamond (D). If all the 3 cards that the player picks are of the same type and same number, they get a Double Bonanza. If all the 3 cards are of the same type or if they all have the same number, they get a Bonanza. Otherwise they do not get a Bonanza. Alan has now picked 3 cards and is awaiting to know if he has got a bonanza. Please help him to know if he has won the Bonanza or not.

Input Format:
There are 3 lines of input.
Each of the line consists of character and integer input, which corresponds to the type of the card and the number in it that Alan picked. The type of card and the number are separated by a single space.

Output Format:
Output should display “Double Bonanza” or “Bonanza” or “No Bonanza” based on the conditions given.
Refer sample input and output for formatting specifications.

Sample Input 1:
S 5
S 5
S 5

Sample Output 1:
Double Bonanza

Sample Input 2:
S 6
S 5
H 5

Sample Output 2:
No Bonanza

a = input().split()
b = input().split()
c = input().split()
a1 = a[0]
a2 = int(a[1])
b1 = b[0]
b2 = int(b[1])
#sauravhathi
c1 = c[0]
c2 = int(c[1])
if ((a2==b2 and b2==c2 and c2==a2) and (a1==b1 and b1 and c1 and c1==a1)):
    print("Double Bonanza")
    #sauravhathi
elif ((a2==b2 and b2==c2 and c2==a2) or (a1==b1 and b1==c1 and c1 and a1)):
    print("Bonanza")
else:
    #sauravhathi
    print("No Bonanza")
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        int a2 = sc.nextInt();
         //sauravhathi
        String b = sc.next();
        int b2 = sc.nextInt();
        String c = sc.next();
        int c2 = sc.nextInt();
        //sauravhathi
        if ((a2==b2 && b2==c2 && c2==a2) && (a.equals(b) && b.equals(c) && c.equals(a))) {
            System.out.println("Double Bonanza");
        } else if ((a2==b2 && b2==c2 && c2==a2) || (a.equals(b) && b.equals(c) && c.equals(a))) {
            System.out.println("Bonanza");
        } else {
             //sauravhathi
            System.out.println("No Bonanza");
        }
    }
}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *