Skip to main content

Featured

Python To read the news

Hello Guys, in this blog we will use Python to read the news. Before this, the concepts of APIs, JSON, Python Libraries should be clear. We are going to use 'newsdataapi' library of Python. The newsdataapi is the official Python client library for the Newsdata.io API. Its primary purpose is to simplify the process of accessing global news data directly from Newsdata.io, allowing developers to integrate news content into their applications without having to manually construct HTTP requests. It acts as a wrapper around the API, handling the complexities of authentication, request parameters, and response parsing. So Lets Start. Making Python to read the online news Step 1: Get your API key Sign Up : Go to the Newsdata.io website and create a free account. The free plan typically offers a limited number of credits per day (e.g., 200 credits). Get the Key : Once you've created and verified your account, your unique API key will be available on your dashboard. Copy this key,...

Rock, Paper, Scissor Game in Java

We can make a simple rock, paper, scissor game in java. Heres, the code:


 import java.util.Scanner;

import javax.lang.model.util.ElementScanner14;

import java.util.Random;

public class App {

    public static void main(String[] args) throws Exception {

        Scanner scan = new Scanner(System.in);

        Random rand = new Random();


        int rand_1 = rand.nextInt(3);


        System.out.println("\nRock, Paper, Scissior Game");

        int trial = 1;

        int player_score = 0;

        int computer_score = 0;


        while (trial<=5) {

            System.out.println("\n0) Rock");

            System.out.print("1) Paper");

            System.out.print("\n2) Scissior");


            System.out.print("\nEnter the choice number: ");

            int choice = scan.nextInt();

            

            // System.out.println(rand_1);


            if (choice == rand_1) {

                System.out.println("Player and Computer Selected Same ");

                // System.out.println("Computer Choice: "+ rand_1);

            } else {


                switch (choice) {

                    case 0:

                        System.out.println("Computer choice: "+ rand_1);

                        if(rand_1<2){

                            if(0<rand_1){

                                System.out.println("Computer wins Match round "+ trial);

                                computer_score = computer_score+1;

                            }

                        }else{

                            System.out.println("Player wins Match round "+ trial);

                            player_score = player_score+1;

                        }

                        break;

                    case 1:

                        System.out.println("Computer choice: "+ rand_1);

                        if(0<rand_1){

                            if(1<rand_1){

                                System.out.println("Computer wins Match round "+ trial);

                                computer_score = computer_score+1;

                            }

                        }else{

                            System.out.println("Player wins Match round "+ trial);

                            player_score = player_score+1;

                        }

                        break;

                    case 2:

                        System.out.println("Computer choice: "+ rand_1);

                        if(rand_1<1){

                            if(rand_1<2){

                                System.out.println("Computer wins Match round "+ trial);

                                computer_score = computer_score+1;

                            }

                        }else{

                            System.out.println("Player wins Match round "+ trial);

                            player_score = player_score+1;

                        }

                        

                        break;

                    default:

                        System.out.println("Wrong input");

                        break;

                }   

            }

            trial = trial+1;

        }

        System.out.println("\nPlayer Score: "+ player_score);

        System.out.println("Computer Score: "+computer_score);

    

        if (player_score>computer_score) {

            int sp = player_score-computer_score;

            System.out.println("\nPlayer won the game by " + sp);

        } else if(computer_score>player_score) {

            int cp = computer_score-player_score;

            System.out.println("\nPlayer lose the game by "+cp);

        }else{

            System.out.println("\nNo one wins the game");

        }

    }


}


Comments

Popular Posts