Sunday, February 16, 2020

how to program for reading the ASCII code of a character and vice versa in C language

#include <stdio.h>
#include <stdlib.h>


void main()
{
    char x;
 int n;

printf("\n enter a character");
scanf("%c",&x);
printf ("\n given character is  %c", x);
printf ("\n ASCII code is %d\n " , x);
printf("\n enter a ASCII code");
scanf("%d",&n);
printf ("\n ASCII code is  %d", n);
printf ("\n equivalent character is %c", n);
getch();
}

output:
 enter a charactera

 given character is  a
 ASCII code is 97

 enter a ASCII code65

 ASCII code is  65
 equivalent character is A

how to Program for reading integers, characters and strings from the keyboard and displaying them in C language

#include <stdio.h>
#include <stdlib.h>

void main()
{int i;
char c , a[20];
printf("\n enter a character");
scanf("%c",&c);
printf("\n enter an integer");
scanf("%d",&i);
printf("\n enter a string");
scanf("%s",a);
printf("\n given character = %c",c);
printf("\n given integer = %d",i);
printf("\n given string = %s",a);
getch();
}

output:
 enter a charactera

 enter an integer123

 enter a stringanildurgam

 given character = a
 given integer = 123
 given string = anildurgam

How to Addition, Subtraction, Multiplication, Division and Modulus operation on two integers in C language

#include <stdio.h>
#include <stdlib.h>

void main()
{ int a,b;
printf("\n enter two values: ");
scanf("%d %d",&a,&b);
printf("\n a + b = %d", a+b);
printf("\n a - b = %d", a-b);
printf("\n a * b = %d", a*b);
printf("\n a / b = %d", a/b);
printf("\n a modulus b = %d", a%b);
getch();
}

output:

 enter two values: 56
64

 a + b = 120
 a - b = -8
 a * b = 3584
 a / b = 0
 a modulus b = 56

Thursday, February 13, 2020

How to add and show the mysql db values in python

import pymysql

conn=pymysql.connect(host="localhost",user="root",password="",db="my_python")
mycursor=conn.cursor()
print("\nPlease enter your choice\n")
#print
choice=int(input("1.add\n2.show\n"))
if choice==1:
    mycursor.execute("INSERT INTO names(id,name) VALUES(4,'premsir');")
    print("->data inserted")
else :
    mycursor.execute("SELECT * FROM names")
    row = mycursor.fetchone()
    while row is not None:
        print(row)
        row = mycursor.fetchone()

conn.commit()
conn.close()

output:

Please enter your choice


1.add
2.show
2
(1, 'ANIL')
(2, 'rakesh')
(3, 'rakesh1')

(4, 'premsir')


example 2:
import pymysql

conn=pymysql.connect(host="localhost",user="root",password="",db="my_python")
mycursor=conn.cursor()
print("\nPlease enter your choice\n")
#print
while True:
    choice=int(input("1.add\n2.show\n3.show all\n"))
    if choice==1:
        mycursor.execute("INSERT INTO names(id,name) VALUES(6,'premsir1');")
        print("->data inserted")
    elif choice ==2 :
        mycursor.execute("SELECT * FROM names")
        row = mycursor.fetchone()
        while row is not None:
            print(row)
            row = mycursor.fetchone()
    else:
        mycursor.execute("SELECT * FROM names")
        rows = mycursor.fetchall()
        print('Total Row(s):', mycursor.rowcount)
        for row in rows:
            print(row)

conn.commit()
conn.close()

output:
Please enter your choice


1.add
2.show
3.show all


how to insert the data into mysql using python

import pymysql

conn=pymysql.connect(host="localhost",user="root",password="",db="my_python")
mycursor=conn.cursor()
mycursor.execute("INSERT INTO names(id,name) VALUES(1,'ANIL');")
print("->data inserted")

conn.commit()
conn.close()

output:




How to connect phpmyadmin mysql with python


import pymysql

conn=pymysql.connect(host="localhost",user="root",password="",db="my_python")
mycursor=conn.cursor()
mycursor.execute("""CREATE TABLE names
            (id int primary key,
            name varchar(20)
            )               
            """)
conn.commit()
conn.close()

output:

Wednesday, February 12, 2020

how to check garbage collector is enable or not

import gc
print(gc.isenabled())

output
True

example2:

import gc
print(gc.isenabled())
gc.disable()
print(gc.isenabled())

output:
True

False

how to declare class in python

class Student:
    def __init__(self,x,y,z):
        self.name=x
        self.rollno=y
        self.marks=z
    def display(self):
        print("name:",self.name)
        print("rollno:",self.rollno)
        print("marks:",self.marks)
 
     
s=Student("anil",100,90)
s.display()

output:
name: anil
rollno: 100
marks: 90

How to write a basic functions in python



Tuesday, February 11, 2020

Tkinter geometry in python

from tkinter import *
import tkinter as tk

# creating Tk windowmaster = Tk()

# setting geometry of tk windowmaster.geometry("200x200+100+100")

# button widgetb1 = Button(master, text = "Click me !")
b1.place(relx = 1, x =-2, y = 2, anchor = NE)

# label widgetl = Label(master, text = "I'm a Label")
l.place(anchor = NW)

# button widgetb2 = Button(master, text = "GFG")
b2.place(relx = 0.5, rely = 0.5, anchor = CENTER)

# infinite loop which is required to# run tkinter program infinitely# until an interrupt occursmainloop()

how to write a basic class in python

Thursday, January 23, 2020

how to write a basic class in python

class Student:
    def read(self):
        print("Reading student class")
     
s=Student()
s.read()

outputL
Reading student class


you can call multiple times
class Student:
    def read(self):
        print("Reading student class")
     
s=Student()
s.read()
s.read()
s.read()
s.read()

output:
Reading student class
Reading student class
Reading student class
Reading student class


example 2:
class Student:
    def __init__(self,x,y,z):
        self.name=x
        self.rollno=y
        self.marks=z
 
       
s=Student("anil",100,90)
print(s.name,s.rollno,s.marks)

output:
anil 100 90

How to Perform Addition, Subtraction, Multiplication, Division and Modulus operation on two integers.


#include<stdio.h>
void main()
{ int a,b;
printf("\n enter two values: ");
scanf("%d %d",&a,&b);
printf("\n a + b = %d", a+b);
printf("\n a - b = %d", a-b);
printf("\n a * b = %d", a*b);
printf("\n a / b = %d", a/b);
printf("\n a modulus b = %d", a%b);
getch();
}

input:

 enter two values: 13  5

output:

 a + b = 18           
 a - b = 8
 a * b = 65
 a / b = 2
 a modulus b = 3

python class topic video