Showing posts with label Blogs. Show all posts
Showing posts with label Blogs. Show all posts
Rock Paper Scissor Game With Python

Rock Paper Scissor Game With Python

Rock Paper Scissor Game With Python

Hello friends. What's up? Hope doing well. Today we are going to make a simple but very interesting game with python. It is a childhood game called " Rock Paper Scissor ". So let's start this.......


First of all trust me this is very easy. Just you should have the basic knowledge about python or any other programming language, and that's it!!!!!!

At first you have to install Python on your computer. For that click HERE, download and install python. This is very easy to install python. 

Then I am using PyCharm to edit the code and also run the code. You can use Visual Code Studio, Sublime Text Editor or Python IDLE etc.. as your wish...
You can download and install PyCharm from HERE ... :)

Now let's come to the coding part.
First I have imported random module. It is preinstalled with python. Then I have taken two variables called comp_score, player_score which initial values are 0. And then I have just welcomed the player with print() function.



import random

comp_score = 0
player_score = 0

print("WELCOME")

Then I have made a function called Choose_option() which will take input from user. I have used only if else and elif condition to take inputs from user.


def Choose_Option():
    user_choice = input("Choose Rock, Paper or Scissors: ")
    if user_choice in ["Rock", "rock", "r", "R", "ROCK"]:
        user_choice = "r"
    elif user_choice in ["Paper", "paper", "p", "P", "PAPER"]:
        user_choice = "p"
    elif user_choice in ["Scissors", "scissors", "s", "S", "SCISSORS"]:
        user_choice = "s"
    else:
        print("I don't understand, try again.")
        Choose_Option()
    return user_choice

Then I have made an another function called Computer_option() which will take input from computer. I have used only if else and elif condition to take inputs from computer. In this case computer will generate a random number from 1 to 3. And then the generated number will be the input from computer.


def Computer_Option():
    comp_choice = random.randint(1, 3)
    if comp_choice == 1:
        comp_choice = "r"
    elif comp_choice == 2:
        comp_choice = "p"
    else:
        comp_choice = "s"
    return comp_choice

Then I have created an infinite while loop. Here I have taken inputs from user and computer and then compared the inputs. Then with sum condition I have started to find out if there is a tie or computer win or player win. Then I have distributed the scores among player and computer.

while True:
    #print("")

    user_choice = Choose_Option()
    comp_choice = Computer_Option()

    #print("")

    if user_choice == "r":
        if comp_choice == "r":
            print("You chose rock. The computer chose rock. You tied.")

        elif comp_choice == "p":
            print("You chose rock. The computer chose paper. You lose.")
            comp_score += 1

        elif comp_choice == "s":
            print("You chose rock. The computer chose scissors. You win.")
            player_score += 1

    elif user_choice == "p":
        if comp_choice == "r":
            print("You chose paper. The computer chose rock. You win.")
            player_score += 1

        elif comp_choice == "p":
            print("You chose paper. The computer chose paper. You tied.")


        elif comp_choice == "s":
            print("You chose paper. The computer chose scissors. You lose.")
            comp_score += 1

    elif user_choice == "s":
        if comp_choice == "r":
            print("You chose scissors. The computer chose rock. You lose.")
            comp_score += 1

        elif comp_choice == "p":
            print("You chose scissors. The computer chose paper. You win.")
            player_score += 1

        elif comp_choice == "s":
            print("You chose scissors. The computer chose scissors. You tied.")

    print("")
    print("Player score: " + str(player_score))
    print("Computer score: " + str(comp_score))
    print("")

Then at last of the loop I have Created a condition. If anyone scores 10 then this will break the loop.
Then with another condition it will find out the winner


    if player_score == 10 or comp_score == 10:
        break

print("Game end....... Let's see the result")

if player_score > comp_score:
    print("Congratulation :)\nYou won the game.")

elif player_score == comp_score:
    print("This is a tie")

else:
    print("You lost the match. Try again")


And now our game is fully ready. Enjoy the game :)

Here is the full code-


'''Created By
Zubaer Mahmud
www.screwdrvr.blogspot.com
'''
import random

comp_score = 0
player_score = 0

print("WELCOME")

def Choose_Option():
    user_choice = input("Choose Rock, Paper or Scissors: ")
    if user_choice in ["Rock", "rock", "r", "R", "ROCK"]:
        user_choice = "r"
    elif user_choice in ["Paper", "paper", "p", "P", "PAPER"]:
        user_choice = "p"
    elif user_choice in ["Scissors", "scissors", "s", "S", "SCISSORS"]:
        user_choice = "s"
    else:
        print("I don't understand, try again.")
        Choose_Option()
    return user_choice


def Computer_Option():
    comp_choice = random.randint(1, 3)
    if comp_choice == 1:
        comp_choice = "r"
    elif comp_choice == 2:
        comp_choice = "p"
    else:
        comp_choice = "s"
    return comp_choice


while True:
    #print("")

    user_choice = Choose_Option()
    comp_choice = Computer_Option()

    #print("")

    if user_choice == "r":
        if comp_choice == "r":
            print("You chose rock. The computer chose rock. You tied.")

        elif comp_choice == "p":
            print("You chose rock. The computer chose paper. You lose.")
            comp_score += 1

        elif comp_choice == "s":
            print("You chose rock. The computer chose scissors. You win.")
            player_score += 1

    elif user_choice == "p":
        if comp_choice == "r":
            print("You chose paper. The computer chose rock. You win.")
            player_score += 1

        elif comp_choice == "p":
            print("You chose paper. The computer chose paper. You tied.")


        elif comp_choice == "s":
            print("You chose paper. The computer chose scissors. You lose.")
            comp_score += 1

    elif user_choice == "s":
        if comp_choice == "r":
            print("You chose scissors. The computer chose rock. You lose.")
            comp_score += 1

        elif comp_choice == "p":
            print("You chose scissors. The computer chose paper. You win.")
            player_score += 1

        elif comp_choice == "s":
            print("You chose scissors. The computer chose scissors. You tied.")

    print("")
    print("Player score: " + str(player_score))
    print("Computer score: " + str(comp_score))
    print("")

    if player_score == 10 or comp_score == 10:
        break

print("Game end....... Let's see the result")

if player_score > comp_score:
    print("Congratulation :)\nYou won the game.")

elif player_score == comp_score:
    print("This is a tie")

else:
    print("You lost the match. Try again")

You can download the code from HERE

UNO vs MICRO vs MEGA 2560โš”

UNO vs MICRO vs MEGA 2560⚔




UNO vs MICRO vs MEGA 2560

Which is the best?๐Ÿค”
The Arduino boards have become one of the most popular microcontrollers on the market with a huge variety of boards. Some Arduino boards are better suited for certain applications. Let’s compare some of the more popular boards that Arduino has created – the Uno, Micro, and Mega 2560 – and see which one is best for your next prototyping, IoT or DIY project, or school robotic project.
Board Size And Price Comparison
The Micro comes in, being true to its name, at 0.7” x 1.9” making it one of the smallest microcontroller boards out there. On the opposite side of the spectrum, the Arduino Mega 2560 board dimensions are about 4” x 2.1”, making it about 6x bigger than the Micro in terms of area size. Arduino Uno dimensions of 2.7” x 2.1” fall somewhere in between the Micro and the Mega 2560.
The pricing for Micro is usually around $19-25 (can be hard to find stock) while the Uno runs around $20-23, and the Mega 2560 comes in at $36 - $39.



{ ~~the price of Arduino boards is seeing very much expensive, because they are real. They are not clone copy. But the ratio of the difference of price is same~~ }
Connectivity
To get connected to your computer and start coding, both the Uno and the Mega 2560 can easily connect with a Standard A/B USB cable, while the Micro will need a Micro-USB cable.
Each of these Arduinos have a different number of Input/Output pins. The board with the most pins is the Mega 2560, which comes in with a whopping 54 Digital Input/Output pins (were 15 of them have PWM) and has 16 Input Analog pins.
Surprisingly, the Micro has the 2nd most pins out of the three, having 20 Digital Input/Output pins (with 7 of them having PWM) and 12 Input Analog pins.
Coming in last is the Uno, which has 14 Digital Input/Output pins (with 6 of them having PWM) and 6 Input Analog pins.
Also good to note, is that both the Uno and Mega 2560 usually come in as through-hole, while the Micro’s pin layout of its header Input/Output’s allows it to fit into any breadboard or system. This means that most Shields are compatible with the Uno and Mega 2560, but the Micro will be out of luck
Processing Power
All three Arduino boards have their own level of processing power, so let’s talk about their frequency/clock speed. The frequency/clock speed on these boards simply means how fast it can execute commands. It was a nice surprise to see that they all have the same clock speed at 16 MHz.
The Flash memory on the Uno and Micro are the same at 32 kB, while the Mega 2560 has 256 kB, giving it 8x more memory space! The Flash memory simply means how big of a sketch/code you can upload to your Arduino, therefore if you have a hefty code the Mega 2560 is the way to go.
Arduino boards use SRAM (Static Random-Access Memory). The Mega 2560 has the most SRAM space with 8 kB, which is 4x more than the Uno, and 3.2x more than the Micro. With more SRAM space, the Arduino has more space to create and manipulate variables when it runs.
Conclusion
The Arduino comparison table below shows a side-by-side comparison of the Uno, Mega 2560, and Micro. Choose your best….
reference: www.arduino.cc
Raspberry Pi โš” Banana Pi

Raspberry Pi ⚔ Banana Pi



Raspberry Pi  Banana Pi
.............................................
Which is the best?


Raspberry Pi is a series of small single board computers, with low cost that can plug into a computer monitor or TV and uses a standard keyboard and mouse.


Banana pi which is a competitor of Raspberry Pi is a new single-board computer that is powered by a much faster processor and RAM. Hardware design of Banana Pi is highly influenced by Raspberry Pi. Thus, Banana Pi is compatible with Raspberry Pi boards. It can also run on various operating systems like Raspbian, NetBSD, Android, Debian etc. It uses Allwinner SoC (System on a chip) and covered by Linux-sunxi port.

Raspberry VS Banana

Raspberry Pi depends on MicroSD and USB for storage whereas Banana pi is fitted with a SATA port, which allows a faster option for connecting mass storage devices like hard drives. ...
Raspberry Pi 3 comes with a quad-core processor with 1 GB RAM whereas Banana pi M3 has an octa-core processor with 2GB RAM.
Raspberry Pi is a capable little device that would enable people from all walks of life to explore computer science and to learn how to program in languages like Python. It is supposed to do everything you would expect from a desktop computer to do, ranging from browsing the internet and playing definition video, making spreadsheets, word processing, and playing games.
Banana Pi is affordable with extensible configurations. Its high performance is driven by Allwinner SoC and 1 GB DDR3 SDRAM. It is highly versatile and compatible with Raspberry pi image. It is for everyone who wants to play and create with computer technologies, instead of simply being a user of electronics.
Raspberry Pi has a small size and accessible price; thus, it was quickly adopted by computer enthusiasts for a project which requires more than a basic microcontroller.
Banana pi provides an open source hardware platform which was produced to run Elastos.org open source operating system. It is dual core, Android 4.2 product which is better than Raspberry Pi. It is highly efficient with several Linux distributions in the market like Debian, Ubuntu, OpenSuse and images that run on Raspberry Pi and Cubieboard. It consists of a Gigabit Ethernet port and a SATA socket.
The size of Banana pi M1 is about the same size as a credit card. It has a potential to run the games smoothly as it supports 1080P high definition video output. The GPIO is compatible with Raspberry Pi and it can run Raspberry pi images directly.
Now just choose yours pi....
 Artificial Intelligence VS Internet of Things

Artificial Intelligence VS Internet of Things

 Artificial Intelligence VS Internet of Things


Hello Friends. Which is the best? AI or IOT ........


What is AI ?

It is all about stimulating intelligence in machines. Artificial intelligence is derived at after stipulative thorough data analysis after serious consideration on derivations and results. AI is beneficial for real-time analysis, post or pre-event processing also. With a strong database, the AI can increase the accuracy of predictions and act accordingly with respect to the commands input by the external stimulus.
Artificial Intelligence is a way of machine learning in fact, which thoroughly examines the pattern and derive on results effectively.AI is a result of collective predictive analysis, continuous analytics and prescriptive analytics. It is just mimicking human intelligence. Most of the current applications, or devices are completely dependent on the AI, as it gives a better interactive environment which is impelling.

What is IoT?

IoT forms an ecosystem of connected devices in a wireless manner which is accessible via the internet.
The connected devices have sensors and have inbuilt embedded systems which can message to the other interconnected devices. The communication of these devices is made possible through effective intelligent technology.
With Iot finding its application in a wide variety of ways like making smart homes, wearable devices, smart cities and even smart vehicles, IoT is expanding day-by-day.

Difference Between Artificial Intelligence and IoT

Aspects

Artificial Intelligence

Internet of Things

Cloud Computing

 Highly Strong – As it facilitates the machine to think, enact and learn from the human instances created.
Both are complimentary in efficiency while Cloud gives a pathway to manage data.
Procuring through the data obtained.




Ai is all about data, it learns and rectifies its performance from errors encountered and evolve in a genuine way. It supports decision making.

In IoT it is mostly captured moments from sensors that bring in data and are stored inside and whenever required the data is pulled in.
Cost
Price is mostly calculated based on each requirement.
Price is substantially lesser.

Scalability
Less Scalable

Scalable being cloud based.

System

AI is all about system behaviour

IoT is inbuilt in a system.

Data

AI needs lot of data, like patterns and understanding the behaviours.
Iot is all about sensors.

Objects
AI does not specifically require objects; it is the system itself.
IoT is mostly concerned about the objects which are embedded with the technology that can capture sensory movements as well as other patterns.

Algorithm

AI is based on deep learning algorithms which are obtained from various sources to design the behaviour of the system.
IoT is all about sensory data that is used to creating an algorithm to formulate the system behaviour.
Behaviour


AI is all about instinctive reactions with respect to the input received.

IoT is a set of predefined responses, that are triggered using the devices and are predefined using specific codes based on algorithms.
Online /Offline


AI is mostly related to online features and responses

IoT is designed in a way, even to work without Internet.
Human Interventions

AI is all about human intrusion.it is either human-human or human-computer
IoT is about transferring data without or with human intervention. It is nothing about human-to-human or computer interaction as it has UIDs (Unique Identifiers).
Artificial Intelligence is all about making your system behave smartly according to human behavior, whereas IoT is all about the sensors of devices. Even though differences are stated, Artificial Intelligence and the Internet of Things do have a clear intersection between them, which is why AI becomes the lead to the future of IoT. Together they bring in a connected level of intelligence which will make computers smarter and not just devices that are interconnected.
Ultrasonic Sensor Tutorial

Ultrasonic Sensor Tutorial

How It Works – Ultrasonic Sensor


Hello friends. This is a complete tutorial on Ultrasonic Sensor.
What is Ultrasonic Sensor?
Ultrasonic Sensor is a sensor which can measure distance. It is compatible with all kinds of micro-controller, such as Arduino, raspberry pi etc.
How does it work?
It emits an ultrasound at 40 000 Hz which travels through the air and if there is an object or obstacle on its path It will bounce back to the module. Considering the travel time and the speed of the sound you can calculate the distance.

Which model of Ultrasonic sensor is being used?
We are using The HC-SR04 Ultrasonic Module. The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground and the VCC pins of the module needs to be connected to the Ground and the 5 volts pins on the Arduino Board respectively and the trig and echo pins to any Digital I/O pin on the Arduino Board.

In order to generate the ultrasound we need to set the Trig on a High State for 10 ยตs. That will send out an 8 cycle sonic burst which will travel at the speed sound and it will be received in the Echo pin. The Echo pin will output the time in microseconds the sound wave traveled.
For example, if the object is 10 cm away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/ยตs the sound wave will need to travel about 294 u seconds. But what you will get from the Echo pin will be double that number because the sound wave needs to travel forward and bounce backward.

So in order to get the distance in cm we need to multiply the received travel time value from the echo pin by 0.034 and divide it by 2.


Components needed for this tutorial


Ultrasonic Sensor HC-SR04
Arduino Board
Breadboard and Jump Wires

 

Source Codes


First we have to define the Trig and Echo pins. In this case they are the pins number 12 and 13 on the Arduino Board and they are named trigPin and echoPin. Then we need a Long variable, named “duration” for the travel time that we will get from the sensor and an integer variable for the distance.
In the setup we have to define the trigPin as an output and the echoPin as an Input and also start the serial communication for showing the results on the serial monitor.
In the loop first we have to make sure that the trigPin is clear so we have to set that pin on a LOW State for just 2 ยตs. Now for generating the Ultra sound wave we have to set the trigPin on HIGH State for 10 ยตs. Using the pulseIn() function you have to read the travel time and put that value into the variable “duration”. This function has 2 parameters, the first one is the name of the echo pin and for the second one we can write either HIGH or LOW. In this case, HIGH means that the pulsIn() function will wait for the pin to go HIGH caused by the bounced sound wave and it will start timing, then it will wait for the pin to go LOW when the sound wave will end which will stop the timing. At the end the function will return the length of the pulse in microseconds. For getting the distance we will multiply the duration by 0.034 and divide it by 2 as we explained this equation previously.  At the end we will print the value of the distance on the Serial Monitor.
Here is the complete source code.
/*
* Ultrasonic Sensor HC-SR04 and Arduino Tutorial
*
* By Zubaer Mahmud
* www.screwdrvr.blogspot.com
*facebook.com/driver3scr/
*/

// defines pins numbers

const int trigPin = 12;
const int echoPin = 13;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);}

 You can download the source Code form Here.