0% found this document useful (0 votes)
23 views

Voting_System_Code

Voting system project for computer system class 12

Uploaded by

Tanish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Voting_System_Code

Voting system project for computer system class 12

Uploaded by

Tanish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Voting System Code

# Voting System

# Dictionaries to store candidate details and votes


candidates = {}
votes = {}

# Function to add a candidate


def add_candidate():
candidate_id = input("Enter Candidate ID: ")
name = input("Enter Candidate Name: ")
candidates[candidate_id] = {"Name": name}
votes[candidate_id] = 0 # Initialize vote count to 0
print(f"Candidate {name} added successfully!")

# Function to vote for a candidate


def vote():
print("\nCandidates List:")
for cid, details in candidates.items():
print(f"ID: {cid}, Name: {details['Name']}")

candidate_id = input("\nEnter Candidate ID to vote for: ")


if candidate_id in candidates:
votes[candidate_id] += 1
print("Vote cast successfully!")
else:
print("Invalid Candidate ID!")

# Function to view the voting results


def view_results():
if votes:
print("\nVoting Results:")
for cid, count in votes.items():
print(f"Candidate {candidates[cid]['Name']} has {count} votes.")
else:
print("No votes cast yet.")

# Main menu
def main():
while True:
print("\nVoting System")
print("1. Add Candidate")
print("2. Vote")
print("3. View Results")
print("4. Exit")
choice = input("Enter your choice: ")

if choice == "1":
add_candidate()
elif choice == "2":
vote()
elif choice == "3":
view_results()
elif choice == "4":
print("Exiting system...")
break
else:
print("Invalid choice! Please try again.")

# Run the program


if __name__ == "__main__":
main()

You might also like