Thursday 18 April 2019

Check whether a given number is Automorphic number or not

// C program to check whether the number is automorphic or not
#include<stdio.h>
bool isAutomorphic(int N)
{
int sq = N * N;
while (N > 0)
{
if (N % 10 != sq % 10)
return false;
// Reduce N and square
N /= 10;
sq /= 10;
}
return true;
}
int main()
{
//Fill the code
int N;
scanf(“%d”,&N);
isAutomorphic(N) ? printf(“Automorphic”) : printf(“Not Automorphic”);
return 0;
}

Program to check if a given number is a strong number or not

Program to check if a given number is a strong number or not is discussed here. A strong number is a number in which the sum of the factorial of the digits is equal to the number itself.
check if a given number is strong number or not
#include<bits/stdc++.h>
using namespace std;
int fact(int num)
{
int res=1;
while(num>0)
{
res*=(num--);
}
return res;
}
bool isStrong(int num)
{
int p=num;
int res=0;
while(p>0)
{
res+=fact(p%10);
p/=10;
}
if(res==num)
return 1;
return 0;
}



int main()
{
int num=123;
cout<<isStrong(num);
}

Program to Find if number is Armstrong Number or Not in C++ C

#include<bits/stdc++.h>
using namespace std;
bool isArm(int num)
{
int ans=0;
int p=num;
while(num>0)
{
int x=num%10;
ans+=x*x*x;
num/=10;
}
if(p==ans)
return 1;
return 0;
}
int main()
{
cout<<isArm(371);
}

Program to check number is Prime or Not in C++

#include<bits/stdc++.h>
using namespace std;
bool isPrime(int num)
{
int p=num;
if(num%2==0)
return 0;
for(int i=3;i*i<=p;i+=2)
{
if(num%i==0)
return 0;
}
return 1;
}

int main()
{
int num=91;
cout<<isPrime(num);
}

LCM of Two Number Program in C++

// LCM of two number is a*b divided by gcd/hcf of two number
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int __gcd(int a,int b)
{
if(b==0)
return a;
return __gcd(b,a%b);
}
int main()
{
int a=12;
int b=6;
int lcm=(a*b)/__gcd(a,b);
cout<<lcm;
}

Program to Calculate GCD or HCF of Two Numbers in C++ (No STL)

// mail me @ mujtaba.aamir1@gmail.com for c++,python notes for free.....
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int __gcd(int a,int b)
{
if(b==0)
return a;
return __gcd(b,a%b);
}
int main()
{
int a=12;
int b=6;
cout<<__gcd(a,b);
}

String to Char Array and Char Array to String Conversion in C++ Simple Approch

#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main()
{
char s[]="stringwith-hyphen";
int size=sizeof(s)/sizeof(s[0]);
char ch[size];
int j=0;
for(int i=0;i<size;i++)
{
if(s[i]=='-')
ch[j++]=s[i];
}
for(int i=0;i<size;i++)
{
if(s[i]!='-')
ch[j++]=s[i];
}
for(int i=0;i<size;i++)
s[i]=ch[i];

// Char Array to String conversion using constructor
// Method 1

string s1(s);

// Method 2

string s2="";
for(int i=0;i<size;i++)
s2+=s[i];
printf("%s\n",s);
cout<<s2;


}

Sunday 25 November 2018

Count All Increasing Sub Sequences GeeksForGeeks Python Program

for _ in range(int(input())):
    n=int(input());
    l=list(map(int,input().split()));
    lz=[0]*10;
    for i in range(len(l)):
        for j in range(l[i]-1,-1,-1):
            lz[l[i]]+=lz[j];
        lz[l[i]]+=1;
    print(sum(lz));
    
    

Monday 19 November 2018

Water Jug Problem in Artificial intelligence Simple Approch

Water Jug Problem:

Problem: You are given two jugs, a 4-gallon one and a 3-gallon one.Neither has any measuring mark on it.There is a pump that can be used to fill the jugs with water.How can you get exactly 2 gallons of water into the 4-gallon jug.

Solution:
The state space for this problem can be described as the set of ordered pairs of integers (x,y)
Where,
X represents the quantity of  water in the 4-gallon jug  X= 0,1,2,3,4
Y represents the quantity of water in 3-gallon jug Y=0,1,2,3
Start State: (0,0)
Goal State: (2,0)
Generate production rules for the water jug problem
Production Rules:
Rule
State
Process
1
(X,Y | X<4)
(4,Y)
{Fill 4-gallon jug}
2
(X,Y |Y<3)
(X,3)
{Fill 3-gallon jug}
3
(X,Y |X>0)
(0,Y)
{Empty 4-gallon jug}
4
(X,Y | Y>0)
(X,0)
{Empty 3-gallon jug}
5
(X,Y | X+Y>=4 ^ Y>0)
(4,Y-(4-X))
{Pour water from 3-gallon jug into 4-gallon jug until 4-gallon jug is full}
6
(X,Y | X+Y>=3 ^X>0)
(X-(3-Y),3)
{Pour water from 4-gallon jug into 3-gallon jug until 3-gallon jug is full}
7
(X,Y | X+Y<=4 ^Y>0)
(X+Y,0)
{Pour all water from 3-gallon jug into 4-gallon jug}
8
(X,Y | X+Y <=3^ X>0)
(0,X+Y)
{Pour all water from 4-gallon jug into 3-gallon jug}
9
(0,2)
(2,0)
{Pour 2 gallon water from 3 gallon jug into 4 gallon jug}


Initialization:
Start State: (0,0)
Apply Rule 2:
(X,Y | Y<3)    ->
(X,3)
{Fill 3-gallon jug}
Now the state is (X,3)

Iteration 1:
Current State: (X,3)
Apply Rule 7:
(X,Y | X+Y<=4 ^Y>0)
(X+Y,0)
{Pour all water from 3-gallon jug into 4-gallon jug}
Now the state is (3,0)

Iteration 2:
Current State : (3,0)
Apply Rule 2:
(X,Y | Y<3)    ->
(3,3)
{Fill 3-gallon jug}
Now the state is (3,3)

Iteration 3:
Current State:(3,3)
Apply Rule 5:
(X,Y | X+Y>=4 ^ Y>0)
(4,Y-(4-X))
{Pour water from 3-gallon jug into 4-gallon jug until 4-gallon jug is full}
Now the state is (4,2)

Iteration 4:
Current State : (4,2)
Apply Rule 3:
(X,Y | X>0)
(0,Y)
{Empty 4-gallon jug}
Now state is (0,2)

Iteration 5:
Current State : (0,2)
Apply Rule 9:
(0,2)
(2,0)
{Pour 2 gallon water from 3 gallon jug into 4 gallon jug}
Now the state is (2,0)

Goal Achieved.

State Space Tree:
 

Thursday 15 November 2018

Longest Increasing Sub Sequences with Dynamic Programming in Python | C++ | C

# Author Mohd Mujtaba @ Play with C Plus
def LIS(l):
    n=len(l);
    l1=[1]*n;
    for i in range(n):
        for j in range(0,i):
            if(l[i]>l[j]):
                l1[i]=max(l1[j]+1,l1[i]);
    print(max(l1));
for _ in range(int(input())):
    n=int(input());
    l=list(map(int,input().split()));
    LIS(l);
   

Monday 8 October 2018

Insertion, Deletion ,Searching at First ,Last , At Given Position in Linked List Implementation in C++

#include<bits/stdc++.h>
using namespace std;
struct node
{
node *link;
int data;
}*start=NULL;
// INSERTION INTO LINKED LIST
void insertNode(int data)
{
node *temp=new node;
temp->link=NULL;
temp->data=data;
if(start==NULL)
{
start=temp;
return;
}
else
{
node *ptr=start;
while(ptr->link!=NULL)
{
ptr=ptr->link;
}
ptr->link=temp;
}
}
void insertInBetween(int data,int search)
{
node *temp=new node;
temp->data=data;
temp->link=NULL;
node *ptr=start;
while(ptr->link!=NULL and ptr->data!=search)
ptr=ptr->link;
temp->link=ptr->link;
ptr->link=temp;
}
void insertFirst(int data)
{
node *temp=new node;
temp->data=data;
temp->link=start;
start=temp;
}
void insertInBetweenBefore(int data,int search)
{
node *prev=NULL,*ptr=start,*temp=new node;
temp->data=data;
while(ptr->link!=NULL and ptr->data!=search)
{
prev=ptr;
ptr=ptr->link;
}
temp->link=prev->link;
prev->link=temp;
}

// ?? VARIOUS LINKED LIST DELETION OPERATIONS ?? //
void deleteFirst()
{
node *ptr=start;
if(ptr->link==NULL)
start=NULL;
else
start=ptr->link;

delete(ptr);
}
void deleteAtPosition(int pos)
{
node *ptr=start;
node *prev=NULL;
int count=0;
while(ptr->link!=NULL and count!=pos)
{
prev=ptr;
count+=1;
ptr=ptr->link;
}
prev->link=ptr->link;
delete(ptr);
}

void deleteLast()
{
node *ptr=start,*prev=NULL;
while(ptr->link!=NULL)
{
prev=ptr;
ptr=ptr->link;
}
prev->link=NULL;
delete(ptr);
}

void disp()
{
node *ptr=start;
while(ptr!=NULL)
{
cout<<" -->"<<ptr->data;
ptr=ptr->link;
}
}

int main()
{
insertNode(10);
insertNode(20);
insertNode(30);
insertNode(40);
cout<<"BEFORE\n";
disp();
cout<<"\nINSERTION AFTER 30\n";
insertInBetween(35,30);
disp();
cout<<"\nINSERTION AT FIRST NODE\n";
insertFirst(5);
disp();
cout<<"\nINSERTION BEFORE 30\n";
insertInBetweenBefore(25,30);
disp();
cout<<"\nDELETING FIRST ELEMENT\n";
deleteFirst();
disp();
cout<<"\nDELETING AT GIVEN POSITION =3:\n";
deleteAtPosition(3);
disp();
cout<<"\nDELETING LAST ELEMENT:\n";
deleteLast();
disp();


}

Thursday 27 September 2018

Array Rotation Implementation in C++ and C

#include<bits/stdc++.h>
using namespace std;

void rotate(int a[],int n)
{
int j;
for(int i=0;i<6;i++)
{
int b=a[0];
for(j=0;j<6;j++)
{
a[j]=a[j+1];
}
a[j]=b;
}


}

int main()
{
int arr[]={1,2,3,4,5,6},n=2;
rotate(arr,n);
// n== rotate by
for(int i=0;i<6;i++)
cout<<arr[i]<<" ";

}

Friday 6 July 2018

Library Management System in Python Complete Program

# CANSOLE BASED PROJECT
import os;
import time;
#************************************ WELCOME SCREEN **********************************
def welcome():
    os.system("cls");
    os.system("color 1A");
    time.sleep(0.3);
    print(" ".rjust(78,"="))
    time.sleep(1/4);
    print("                     WELCOME TO CETPA LIBRARY MANAGEMET SYSTEM")
    time.sleep(1/4);
    print("                                INDRA NAGAR LUCKNOW UP")
    time.sleep(1/4);
    print("                        Console Based PROJECT BY MOHD MUJTABA(Batch-13June)")
    time.sleep(1/4);
    print(" ".rjust(78,"="))
    time.sleep(1/4);
    menu();
#******************************** MAIN MENU *************************************             
def menu():
    print(" ".rjust(78,"="))
    print("                     LOGIN MANAGEMENT SYSTEM<AUTHORISED>")
    print(" ".rjust(78,"="))
    print("""   1. STUDENT
   2. ADMIN/STAFF""");
    choice=int(input("     Enter Your Choice:"))
    if(choice!=1 and choice!=2):
        print("Wrong Choice Enter Again:!");
        os.system("cls");
        menu();
    elif(choice==1):
        studentMenu();
    elif(choice==2):
        adminMenu();
#************************** STUDENT MENU *******************************
def studentMenu():
    os.system("cls");
    os.system("color 2E");
    print(" ".rjust(78,"="))
    print("                     STUDENT MENU WINDOW<AUTHORISED>")
    print(" ".rjust(78,"="))
    print("""    1. EXISTING USER(LOGIN)
    2. NEW USER(SIGN UP)
    3. DELETE USER
    4. LOG OFF
    5. EXIT.""");
    choice=input("        Enter Your Choice:")
    if(choice=='1'):
        studLogin();
         
    elif(choice=='2'):
        studRegister();
    elif(choice=='3'):
        studdelete();
    elif(choice=='4'):
        welcome();
    elif(choice=='5'):
        exit();
    else:
        print("Wrong Choice Try Again:");
        time.sleep(1);
        studentMenu();
#*********************** STUDENT REGISTRATION ************************
def studRegister():
        os.system("cls");
        os.system("color 3F");
        check=1;
        print(" ".rjust(78,"="))
        print("                     NEW STUDENT REGISTRATION WINDOW")
        print(" ".rjust(78,"="))
        f=open('D:/Python Lucknow/studreg.txt'); 

        id=input("Enter STUDENT ID(MUST BE UNIQUE):");
        while True:
                l=f.readline().split(",");
                print(l);
                if(id==l[0]):
                        print("Record Already Exist! Kindly Proceed To Login:");
                        time.sleep(2);
                        f.close();
                        studentMenu();
                if(l==['']):
                        break;
        name=input("Choose Your Name(MIN 4 CHARACTER):");
        username=name[:4]+str(id);
        while(check):
                pwd=input("Enter New Password:")
                cnfpwd=input("Re-Enter Password:");
                if(pwd!=cnfpwd):
                        print("Password Do not Match! Kindly Enter Again!");
                        check=1;
                else:
                        break;
        filecontent=str(id)+","+name+","+username+","+pwd+"\n";
        open('D:/Python Lucknow/studreg.txt',"a").write(filecontent);
        print("Acocunt Created Successfully Wait(2 Second:)");
        time.sleep(2);
        f.close();
        studentMenu();
    
#*********************** STUDENT LOGIN ******************************
def studLogin():
        os.system("cls");
        os.system("color 4E");
        print(" ".rjust(78,"="))
        print("                     STUDENT LOGIN WINDOW<AUTHORISED>")
        print(" ".rjust(78,"="))
        user=input("Enter UserName:");
        pwd=input("Enter Password:");
        f=open('D:/Python Lucknow/studreg.txt');
        l=f.readlines()
        m=0
        for i in l:
                print(i.split(','))
                if (user==i.split(',')[2] and pwd==i.split(',')[3].split()[-1]):
                        print("Login SuccessFul: Wait Redirecting.....");
                        time.sleep(1/4);
                        f.close();
                        studMainMenu(i);
                        break;
        if m==0:
                print("Invalid UserName Or Password! Kindly Enter Again!:");
                time.sleep(1);
                f.close();
                studLogin();
        f.close();
            
#******************** STUDENT DELETE USER **********************************
def studdelete():
        os.system("cls");
        os.system("color 5B");
        userid=input("Enter Your UserName(99 to Exit):");
        f=open("D:/Python Lucknow/studreg.txt");
        f1=open("D:/Python Lucknow/studreg1.txt","w");
        while True:
                if(userid==str(99)):
                        studentMenu();
                l=f.readline().split(",")
                print(l);
                if(l==['']):
                        print("User Id Does Not Exist:\nKindly Enter Again");
                        f.close();
                        f1.close();
                        studdelete();
                if(l[2]==userid):
                        f1.write(f.read());
                        f1.close();
                        f.close();
                        os.remove("D:/Python Lucknow/studreg.txt");
                        os.rename("D:/Python Lucknow/studreg1.txt","D:/Python Lucknow/studreg.txt");
                        print("Record Deleted!.....Wait(2 Sec)");
                        time.sleep(3/2);
                        studentMenu();
                filecontent=",".join(l);
                f1.write(filecontent);
#*************************STUDENT <MAIN MENU>*********************
def studMainMenu(l):
    os.system("cls");
    os.system("color 4A");
    print(" ".rjust(78,"="))
    time.sleep(1/3);
    print(" ".rjust(78,"="))
    print("                               STUDENT MAIN MENU<AUTHORISED>")
    time.sleep(1/2);
    print(" ".rjust(78,"="))
    print("""\n\n   1. ISSUE BOOK
   2. RETURN BOOK
   3. VIEW ISSUED BOOK
   4. LOG OFF.
   5. EXIT """);
    ch=0;
    while(ch<1 or ch>5):
        ch=int(input("Enter Your Choice....."));
        if(ch==1):
            issueBook(l);
        elif(ch==2):
            returnBook(l);
        elif(ch==3):
            viewIssuedBook(l);
        elif(ch==4):
            studentMenu();
        elif(ch==5):
            exit();
        else:
            print("Wrong Choice!! Enter Again...");
#********************** ISSUE BOOK(STUDENT) **********************
def issueBook(l):
    os.system("cls");
    os.system("color 5B");
    
    id=l.split(",")[0];
    name=l.split(",")[1];
    print("Student Name:",name,"  Id:",id);
    f=open("D:/Python Lucknow/addbook.txt","r");
    f1=open("D:/Python Lucknow/issuedbook.txt","a");
    f2=open("D:/Python Lucknow/addbook1.txt","w");
    bname=input("Enter BOOK NAME:");
    check=0;
    while True:
        rl=f.readline().split(",");
        if(rl==['']):
            print("No Book's Found:Redirecting...");
            time.sleep(1);
            f.close();
            f1.close();
            f2.close();
            studMainMenu(l);
            break;
        elif(bname==rl[1]):
            file=id+","+name+","+bname+"\n";
            f1.write(file);
            f.close();
            f1.close();
            f2.close();
            check=1;
            break;
    if(check==1):
        f=open("D:/Python Lucknow/addbook.txt","r").readlines();
        for i in f:
            p=i.split(",");
            if(p[1]==bname):
                p[3]=str(int(p[3])+1);
                open("D:/Python Lucknow/addbook1.txt","a").write(",".join(p));
                check=2;
            else:
                open("D:/Python Lucknow/addbook1.txt","a").write(",".join(p));
    if(check==2):
        f2.close();
        os.remove("D:/Python Lucknow/addbook.txt");
        os.rename("D:/Python Lucknow/addbook1.txt","D:/Python Lucknow/addbook.txt");
        print("Book Issued....Redirecting.....");
        time.sleep(1);
        studMainMenu(l);
#***************************** RETURN BOOK<STUDENT> ******************************
def returnBook(l):
    os.system("cls");
    os.system("color 9E");
    check=0;
    f=open("D:/Python Lucknow/issuedbook.txt");
    line=l.split(",");
    count=0;
    while True:
        rl=f.readline().split(",");
        if(rl==['']):
            if(count==0):
                print("No Book is Issued...Redirecting....");
                time.sleep(1.3);
                f.close();
                studMainMenu(l);
            else:
                f.close();
                break;
        elif(line[1]==rl[1]):
            print(rl);
            count=1;
      
    name=input("Enter BOOK NAME:");
    #f=open("D:/Python Lucknow/addbook1.txt","w");
    f1=open("D:/Python Lucknow/issuedbook1.txt","w");
    f2=open("D:/Python Lucknow/addbook1.txt","w");
    f3=open("D:/Python Lucknow/issuedbook.txt");
    
    while True:
        if(name==str(99)):
            studentMainMenu(l);
        l3=f3.readline().split(",")
        print(l3);
        if(l3==['']):
            print("No Book Found! Redirecting.....");
            time.sleep(1);
            f1.close();
            f2.close();
            f3.close();
            os.remove("D:/Python Lucknow/issuedbook1.txt");
            os.remove("D:/Python Lucknow/addbook1.txt");
            studMainMenu(l);
        elif(l3[2].split("\n")[0]==name and line[1]==l3[1]):
            f1.write(f3.read());
            f1.close();
            f3.close();
            f2.close();
            check=1;
            os.remove("D:/Python Lucknow/issuedbook.txt");
            os.rename("D:/Python Lucknow/issuedbook1.txt","D:/Python Lucknow/issuedbook.txt");
            break;
        else:
            filecontent=",".join(l3);
            f1.write(filecontent);

    if(check==1):
        f=open("D:/Python Lucknow/addbook.txt","r").readlines();
        for i in f:
            p=i.split(",");
            if(p[1]==name):
                p[3]=str(int(p[3])-1);
                open("D:/Python Lucknow/addbook1.txt","a").write(",".join(p));
                check=2;
            else:
                open("D:/Python Lucknow/addbook1.txt","a").write(",".join(p));
    if(check==2):
        f2.close();
        os.remove("D:/Python Lucknow/addbook.txt");
        os.rename("D:/Python Lucknow/addbook1.txt","D:/Python Lucknow/addbook.txt");
        print("Record Deleted!.....Wait(2 Sec)");
        time.sleep(3/2);
        studMainMenu(l);
#******************************** VIEW ISSUED BOOK<STUDENT>*********************
def viewIssuedBook(q):
    p=q.split(",");
    os.system("cls");
    os.system("color 6E");
    f=open("D:/Python Lucknow/issuedbook.txt");
    print("UID\t\tNAME\t\t\BOOK NAME");
    while(True):
        l=f.readline().split(",");
        if(l==['']):
            f.close();
            ch=input("Enter (Y/y) To Go Back:");
            if(ch=='y' or ch=='Y'):
                studMainMenu(q);
                break;
            else:
                exit();
        elif(p[1]==l[1]):
            print(l[0],'\t\t',l[1],'\t\t',l[2]);
    
#********************* ADMIN MENU *******************************
def adminMenu():
    os.system("cls");
    os.system("color 9F");
    
    print(" ".rjust(78,"="))
    print("                     ADMINSTRATIVE MENU WINDOW<AUTHORISED>")
    print(" ".rjust(78,"="))
    print("""    1. EXISTING USER(LOGIN)
    2. NEW USER(SIGN UP)
    3. DELETE USER
    4. LOG OFF
    5. EXIT.""");
    choice=input("        Enter Your Choice:")
    if(choice=='1'):
        adminLogin();
    elif(choice=='2'):
        adminRegister();
    elif(choice=='3'):
        admindelete();
    elif(choice=='4'):
        welcome();
    elif(choice=='5'):
        exit();
        
    else:
        print("Wrong Choice Try Again:");
        time.sleep(1);
        adminMenu();
#*********************** ADMIN REGISTRATION ************************
def adminRegister():
    os.system("cls");
    os.system("color 4F");
    
    check=1;
    print(" ".rjust(78,"="))
    print("                     NEW ADMIN REGISTRATION WINDOW")
    print(" ".rjust(78,"="))
    f=open('D:/Python Lucknow/admin.txt'); 

    id=input("Enter ADMIN ID(MUST BE UNIQUE):");
    while True:
        l=f.readline().split(",");
        print(l);
        if(id==l[0]):
            print("Record Already Exist! Kindly Proceed To Login:");
            time.sleep(2);
            f.close();
            adminMenu();
        if(l==['']):
                break;
    name=input("Enter ADMIN Name(MIN 4 CHARACTER):");
    username=name[:4]+str(id);
    while(check):
        pwd=input("Enter New Password:")
        cnfpwd=input("Re-Enter Password:");
        if(pwd!=cnfpwd):
            print("Password Do not Match! Kindly Enter Again!");
            check=1;
        else:
            break;
    filecontent=str(id)+","+name+","+username+","+pwd+"\n";
    print(filecontent);
    open('D:/Python Lucknow/admin.txt',"a").write(filecontent);
    print("Acocunt Created Successfully Wait(2 Second:)");
    time.sleep(2);
    f.close();
    adminMenu();
    
#*********************** ADMIN LOGIN ******************************
def adminLogin():
    os.system("cls");
    os.system("color 8E");
    print(" ".rjust(78,"="))
    print("                     ADMIN LOGIN WINDOW<AUTHORISED>");
    print(" ".rjust(78,"="))
    user=input("Enter UserName(99 for Main Menu):");
    pwd=input("Enter Password:");
    f=open('D:/Python Lucknow/admin.txt');
    l=f.readlines()
    m=0
    
    for i in l:
        if(user=='99'):
            welcome();
            break;
        print(i.split(','))
        if (user==i.split(',')[2] and pwd==i.split(',')[3].split()[-1]):
                print("Login SuccessFul:");
                m=1;
                f.close();
                adminMainMenu(i);     
    if m==0:
        print("Invalid UserName Or Password:Redirecting...");
        time.sleep(1/2);
        f.close();
        adminLogin();
         
#******************** ADMIN DELETE USER ********************************
def admindelete():
    print(" ".rjust(78,"="))
    print("                    DELETE USER WINDOW<AUTHORISED>")
    print(" ".rjust(78,"="))
    userid=input("Enter Your UserName(99 to Exit):");
    f=open("D:/Python Lucknow/admin.txt");
    f1=open("D:/Python Lucknow/admin1.txt","w");
    while True:
        if(userid==str(99)):
            adminMenu();
        l=f.readline().split(",")
        print(l);
        if(l==['']):
            print("User Id Does Not Exist:\nKindly Enter Again");
            f.close();
            f1.close();
            admindelete();
        if(l[2]==userid):
            f1.write(f.read());
            f1.close();
            f.close();
            os.remove("D:/Python Lucknow/admin.txt");
            os.rename("D:/Python Lucknow/admin1.txt","D:/Python Lucknow/admin.txt");
            print("Record Deleted!.....Wait(2 Sec)");
            time.sleep(3/2);
            adminMenu();
    filecontent=",".join(l);
    f1.write(filecontent);
# ************************* ADMIN MAIN MENU *****************************
def adminMainMenu(l):
    os.system("cls");
    os.system("color 9F");
    time.sleep(1/5);
    print(" ".rjust(78,"="))
    time.sleep(1/5);
    print("                     WELCOME TO CETPA LIBRARY MANAGEMET SYSTEM")
    time.sleep(1/5);
    print("                                INDRA NAGAR LUCKNOW UP")
    time.sleep(1/5);
    print("                        Console Based PROJECT BY MOHD MUJTABA")
    time.sleep(1/5);
    print(" ".rjust(78,"="))
    time.sleep(1/4);
    print(" ".rjust(78,"="))
    print("                               ADMIN MAIN MENU<AUTHORISED>")
    print(" ".rjust(78,"="))
    print("""\n\n   1. ADD NEW BOOK
   2. Delete BOOK
   3. View BOOKS
   4. Charge Fine
   5. Total Fine Collected
   6. LOG OFF.
   7. EXIT""");
#5. Fine Collected(Student Wise)
    choice=input("Enter Your Choice.......:");
    if(choice=='1'):
        addBook(l);
    elif(choice=='2'):
        delBook(l);
    elif(choice=='3'):
        viewBook(l);
    elif(choice=='4'):
        chargeFine(l);
##    elif(choice==5):
##        totalFineStudentWise(l);
    elif(choice=='5'):
        totalFine(l);
    elif(choice=='6'):
        adminMenu();
    elif(choice=='7'):
        exit();
    else:
        print("Wrong Option Selected! Try again..:");
        time.sleep(3/2);
        adminMainMenu(l);
#************************* ADD BOOK ********************************
def addBook(l):
    os.system("cls");
    os.system("color 4F");
    f=open("D:/Python Lucknow/addbook.txt","a");
    f1=open("D:/Python Lucknow/addbook.txt");

    isbn=input("Enter ISBN Number:");
    while True:
        l=f1.readline().split(",");
        print(l);
        
        if(isbn==l[0]):
            print("Record Already Exist! Redirecting To Main Menu......:");
            time.sleep(1.5);
            f.close();
            f1.close();
            adminMainMenu(l);
            
            
        if(l==['']):
                break;
    name=input("Enter Book Name:");
    author=input("Enter Author Name:");
    quantity=input("Enter Quantity:");
    issued=0;
    file=isbn+","+name+","+quantity+","+str(issued)+","+author+"\n"
    f.write(file);
    print("Record Updated Successfully.......");
    ch=input("Do You Want To Add More....(Y/N):");
    f.close();
    f1.close();
    if(ch=="y" or ch=='Y'):     
        addBook();
    else:
        adminMainMenu(l);
#****************************** VIEW BOOK *******************************
def viewBook(l):
    os.system("cls");
    os.system("color 6E");
    f=open("D:/Python Lucknow/addbook.txt");
    print("ISBN\t\tName\t\t\tQuantity\t\tIssued\t\tAuthor");
    while(True):
        l=f.readline().split(",");
        if(l==['']):
            f.close();
            ch=input("Enter (Y/y) To Go Back:");
            if(ch=='y' or ch=='Y'):
                adminMainMenu(l);
            else:
                exit();
        else:
            print(l[0],'\t\t',l[1],'\t\t',l[2],'\t\t',l[3]+'\t\t'+l[4]);    
# ******************************* DELETE BOOK ****************************
def delBook(l):
    print(" ".rjust(78,"="))
    print("                    DELETE BOOK RECORD<ADMIN>")
    print(" ".rjust(78,"="))
    isbn=input("Enter ISBN Number(99 to Exit):");
    f=open("D:/Python Lucknow/addbook.txt");
    f1=open("D:/Python Lucknow/addbook1.txt","w");
    while True:
        if(isbn==str(99)):
            adminMainMenu(l);
        else:
            l=f.readline().split(",")
            if(l==['']):
                print("Book Does Not Exist:\nKindly Enter Again");
                f.close();
                f1.close();
                delBook();
            if(l[0]==isbn):
                f1.write(f.read());
                f1.close();
                f.close();
                os.remove("D:/Python Lucknow/addbook.txt");
                os.rename("D:/Python Lucknow/addbook1.txt","D:/Python Lucknow/addbook.txt");
                print("Record Deleted!.....Wait(2 Sec)");
                time.sleep(3/2);
                adminMainMenu(l);
            else:
                filecontent=",".join(l);
                f1.write(filecontent);
#****************************** CHARGE FINE**************************
def chargeFine(l):
    os.system("cls");
    print(" ".rjust(78,"="))
    print("                    FINE COLLECTION WINDOW<ADMIN>")
    print(" ".rjust(78,"="))
    p=l.split(",");
    uid=p[0];
    name=p[1];
    print(uid,name);
    studid=input("Enter Student UID:");
    f=open("D:/Python Lucknow/studreg.txt","r").readlines();
    p=[i for i in f if(i.split(",")[0]==studid)]
    if(len(p)==0):
        print("NO UID FOUND! Redirecting.....");
        time.sleep(3/2);
        chargeFine(l);
    else:
        print("Student Name: ",p[0].split(",")[1]);
        studname=p[0].split(",")[1];
        bname=input("Enter Book Name for fine to be Charged:");
        f=open("D:/Python Lucknow/addbook.txt","r").readlines();
        p=[i for i in f if(i.split(",")[1]==bname)]
        if(len(p)==0):
            print("NO BOOK FOUND! Redirecting.....");
            time.sleep(3/2);
            chargeFine(l);
        else:
            fine=input("Enter Fine Amount:");
            file=studid+","+studname+","+bname+","+fine+","+uid+","+name+"\n";
            open("D:/Python Lucknow/fine.txt","a").write(file);
            print("Congrats!",studname,"You Have Been Fined for Rs:",fine);
            print("Please Wait Redirecting......");
            time.sleep(1);
            adminMainMenu(l);
#*******************************TOTAL FINE(STUDENT WISE)*******************
#*******************************TOTAL FINE**********************************
def totalFine(l):
    tot=0;
    f=open("D:/Python Lucknow/fine.txt","r").readlines();
    for i in f:
        tot+=int(i.split(",")[3])
    print("Total Fine Collected Till Now:",tot);
    ch=input("Press (Y/y) To Go Back:");
    if(ch=='y' or ch=="Y"):
        adminMainMenu(l);
    else:
        exit();
#************************** CALLING THE MAIN FUNCTION ****************
welcome();

Amazon1Ads