Posts

Arithmetic Operators in python with example

Image
 # Addition of two no in Python..... a = 10 b = 5 add = a + b print ( 'a = 10' ) print ( 'b = 5' ) print ( add ) # Subtraction  of two no in python..... a = 10 b = 5 sub = a - b print ( 'a = 10' ) print ( 'b = 5' ) print ( sub ) # Division of two no in python..... a = 10 b = 5 divide = a / b print ( 'a = 10' ) print ( 'b = 5' ) print ( divide ) # Multiplication of two no in python..... a = 10 b = 5 multi = a * b print ( 'a = 10' ) print ( 'b = 5' ) print ( multi ) ...Output...

Match (Switch) statement in python

# Match (Switch) statement in python..... lang = str ( input ( "What's the programming language you want to learn? : " )) match lang :     case 'JavaScript' :         print ( 'You can become a web developer.' )     case 'Python' :         print ( 'You can become a Data Scientist.' )     case 'PHP' :         print ( 'You can become a backend developer.' )     case 'Java' :         print ( 'You can become a mobile app developer' )     case _:         print ( "The language doesn't matter, what matters is solving problems." )

Making Calculator Using Python

# Making Calculator Using Python..... print ( 'Calculator' ) def sum ( a , b ):     s = a + b     return s def diff ( a , b ):     d = a - b     return d def multi ( a , b ):     m = a * b     return m def divide ( a , b ):     d = a / b     return d def power ( a , b ):     p = a ** b     return p a = int ( input ( 'Enter the 1st values: ' )) b = int ( input ( 'Enter the 2nd values: ' )) print ( '' ) print ( 'Sum of ur number...' ) print ( '-->' , sum ( a , b )) print ( '' ) print ( 'Diff of ur number...' ) print ( '-->' , diff ( a , b )) print ( '' ) print ( 'Multiplaction of ur number...' ) print ( '-->' , multi ( a , b )) print ( '' ) print ( 'Product of ur number...' ) print ( '-->' , divide ( a , b )) print ( '' ) print ( 'Power of ur number...' ) print ( '-->' , power ( a , b )) print ( ...

Making Screen Pet Using Python

Image
 # Making Screen Pet Using Python..... from tkinter import HIDDEN , NORMAL , Tk , Canvas def toggle_eyes ():     current_color = c . itemcget ( eye_left , 'fill' )     new_color = c .body_color if current_color == 'white' else 'white'     current_state = c . itemcget ( pupil_left , 'state' )     new_state = NORMAL if current_state == HIDDEN else HIDDEN     c . itemconfigure ( pupil_left , state = new_state )     c . itemconfigure ( pupil_right , state = new_state )     c . itemconfigure ( eye_left , fill = new_color )     c . itemconfigure ( eye_right , fill = new_color ) def blink ():     toggle_eyes ()     root . after ( 250 , toggle_eyes )     root . after ( 3000 , blink ) def toggle_pupils ():     if not c .eyes_crossed:         c . move ( pupil_left , 10 , - 5 )         c . move ( pupil_right ...

Making Traffic Signal Using Python

Image
 #Making Traffic Signal Using Python..... import turtle as t t . bgcolor ( 'light blue' ) t . speed ( 'slowest' ) t . hideturtle () t . delay ( 0 ) t . pencolor ( '' ) t . goto ( - 150 , 100 ) t . fillcolor ( 'black' ) t . begin_fill () t . pencolor ( 'gray' ) t . forward ( 150 ) t . right ( 90 ) t . forward ( 325 ) t . right ( 90 )   t . forward ( 150 ) t . right ( 90 ) t . forward ( 325 ) t . right ( 90 ) t . end_fill () t . delay ( 0 ) t . pencolor ( '' ) t . goto ( - 75 , 0 ) t . fillcolor ( 'gray' ) t . begin_fill () t . pencolor ( 'white' ) t . circle ( 35 ) t . end_fill () t . delay ( 0 ) t . pencolor ( '' ) t . goto ( - 75 , - 100 ) t . fillcolor ( 'gray' ) t . begin_fill () t . pencolor ( 'white' ) t . circle ( 35 ) t . end_fill () t . delay ( 0 ) t . pencolor ( '' ) t . goto ( - 75 , - 200 ) t . fillcolor ( 'gray' ) t . begin_fill () t . pencolor ( 'white' ) t . ...

Making Rainbow Using Python

Image
 # Making Rainbow Using Python..... # Import turtle package import turtle # Creating a turtle screen object sc = turtle . Screen () # Creating a turtle object(pen) pen = turtle . Turtle () # Defining a method to form a semicircle # with a dynamic radius and color def semi_circle ( col , rad , val ):     # Set the fill color of the semicircle     pen . color ( col )     # Draw a circle     pen . circle ( rad , - 180 )     # Move the turtle to air     pen . up ()     # Move the turtle to a given position     pen . setpos ( val , 0 )     # Move the turtle to the ground     pen . down ()     pen . right ( 180 ) # Set the colors for drawing col = [ 'violet' , 'indigo' , 'blue' ,     'green' , 'yellow' , 'orange' , 'red' ] # Setup the screen features sc . setup ( 500 , 500 ) # Set the screen color to black sc . bgcolor ( 'black' ) # Setup the turtle features pen...

Making Snake Game Using Python

Image
# Making Snake Game Using Python..... import turtle import time import random # Create a Snake-Game using Turtle in Python delay = 0.1 score = 0 high_score = 0 wn = turtle . Screen () wn . title ( "Snake Game" ) wn . bgcolor ( "black" ) wn . setup ( width = 600 , height = 600 ) wn . tracer ( 0 ) head = turtle . Turtle () head . shape ( "circle" ) head . color ( "white" ) head . penup () head . goto ( 0 , 0 ) head .direction = "stop" food = turtle . Turtle () colors = random . choice ([ 'red' , 'green' , 'yellow' ]) shapes = random . choice ([ 'square' , 'triangle' , 'circle' ]) food . speed ( 0 ) food . shape ( shapes ) food . color ( colors ) food . penup () food . goto ( 0 , 100 ) pen = turtle . Turtle () pen . speed ( 0 ) pen . shape ( "circle" ) pen . color ( "white" ) pen . penup () pen . hideturtle () pen . goto ( 0 , 250 ) pen . write ( ...