Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

import mysql.

connector

mydb = mysql.connector.connect(host="localhost",user="prs",passwd="123",database="project")

con=mydb.cursor()

#con.execute("create database project")

#con.execute("use project")

#con.execute("create table login(UserID int(4) primary key,passwd varchar(30))")

#con.execute("create table voter(UserID int(4) primary key,Name varchar(30),DOB date,Address


varchar(100))")

#con.execute("create table party(partyname varchar(10),votecount int(10) default 0)")

def loginput():

u=int(input("Enter UserID "))

p=input("Enter Password ")

def signup():

loginput()

sql="insert into login values(%s,%s)"

val=(u,p)

con.execute(sql,val)

mydb.commit()

print("Account Created Succesfully. Now login.")

nam=input("Enter your name: ")

dob=input("Enter your date of birth(YYYY-MM-DD): ")

addrs=input("Enter your address: ")

sql = "insert into voter (UserID,Name,DOB,Address) values (%s,%s,%s,%s)"

val = (u,nam,dob,addrs)

con.execute(sql,val)

mydb.commit()

def menu():
print ("Select from the following alternatives..")

print ("1 : View User Details \n")

print ("2 : Edit User Details\n")

print ("3 : Cast my vote\n")

print ("4 : View Current Count(ONLY IF ALREADY CASTED YOUR VOTE) \n" )

print ("5 : Exit Program \n")

def update():

z=int(input())

if z==1:

nam=input("Please enter your name ")

sq="update voter set name=%s where UserID=%s"

val=(nam,u)

con.execute(sq,val)

mydb.commit()

print("Data is succesfully changed")

if z==2:

dob=input("Please enter your DOB ")

sq="update voter set DOB=%s where UserID=%s"

val=(dob,u)

con.execute(sq,val)

mydb.commit()

print("Data is succesfully changed")

if z==3:

addrs=input("Please enter your address ")

sq="update voter set Address=%s where UserID=%s"

val=(addrs,u)

con.execute(sq,val)

mydb.commit()

print("Data is succesfully changed")


def view():

con.execute("select * from voter")

d=con.fetchall()

n=u%1000

l1=d[n-1]

print("Name : ",l1[1])

print("DOB : ",l1[2])

print("Address : ",l1[3])

def vote():

l1=("T")

sql="select voted from voter where UserID=%s"

val=(u)

con.execute(sql,val)

l2=con.fetchall()

if l2==l1:

print("You have voted succesfully....")

menu()

else:

m=int(input())

sq="update voter set voted=%s where UserID=%s"

val=("T",u)

con.execute(sq,val)

mydb.commit()

if m==1:

sq="update party set votecount=votecount+1 where partyname=%s"

val="A"

con.execute(sq,val)

mydb.commit()

if m==2:

sq="update party set votecount=votecount+1 where partyname=%s"


val="B"

con.execute(sq,val)

mydb.commit()

if m==3:

sq="update party set votecount=votecount+1 where partyname=%s"

val="C"

con.execute(sq,val)

mydb.commit()

if m==4:

sq="update party set votecount=votecount+1 where partyname=%s"

val="NOTA"

con.execute(sq,val)

mydb.commit()

def votecount():

if l2==l1:

con.execute("select * from party")

data=con.fetchall()

for x in data:

print(x)

else:

print("You haven't casted your vote yet. Please cast your vote to view this information.\n")

print ("\t*********************** ELECTION MANAGEMENT SYSTEM ********************\n")

n=int(input("Press 1 to login OR 2 to register "))

k=0

if n==2:

signup()
if n==1:

loginput()

l=(u,p)

con.execute("select * from login")

data=con.fetchall()

for x in data:

if x==l:

k=1

if k==1:

print("Logged in succesfully...\n")

menu()

y=int(input())

if y==1:

view()

if y==2:

print("Select the detail which is to be edited\n1:Name\n2:DOB\n3:Address")

update()

if y==3:

print("Select one out of the foolowing alternatives\n1. Party A\n2. Party B\n3. Party C\\n4.
NOTA")

vote()

if y==4:

votecount()

if y==5:

break

else:

print("Invalid credentials\nLogin Again...")

You might also like