Python App Project – Python Quiz App In Hindi

Python Quiz App In Hindi :- Aaj Ham Python Quiz App Banane Wale Hai Jisme Ham Quiz Khel Sakte Hai Or Python Quiz Code Me Ham Login Panel And Create Account Bhi Rakhne Wale Hai |

Friends Agar Aapko Python Quiz Code Understand Karne Me Kuch Bhi Problem Hoti Hai To Aap Mujhe Niche Diye Gaye Comment Box Likh Kar Sand Kar Sakte Hai Me Aapko Jarur Help Karunga |

Python Quiz App In Hindi

Aaj Ham Quiz App Ko A to Z Se Cover Karne Wale Hai Is Python Quiz App Me Bahut Sare Function Hone Wale Hai |

Friends Ye Quiz App Code Step 8 Me Divide kiye Gaye Hai Ek Ek Function Alag Alag Create Kiya Gaya Hai Or Bad Me hamne Sab Code Ko Add Kar Diya Hai Or uski Json File With Code Hamne Ek Download Link Me Niche De Rakha Hai | Agar Aapko Kuch Bhi Dikkat Hoti Hai Code Se Related To Aap Mujhse Help Le Sakte Hai |

Friends Sabse Pahle Ham Upper Diye Gaye Image Me Dekh Sakte Hai Or Ek Ek Karke Coding Start Karte Hai Ye Coding Ham Step By Step Karne Wale Hai |

Step 1 : Sabse Pahle Ham Python Ke Kuch InBuilt Function Ko Istemal Karte Hai Or Unhe Import Karte Hai |

import json
import random
import getpass
  • Json :- Json Function Json Format Data Ko Read Karne Ke Liye Istemal Hota Hai |
  • Random :- Random Function Random number Generate Karne Ke Liye Istemal Hota Hai |
  • GetPass :- getpass Function string ke rup me password ko store karta hai |

Step 2 :- Ham Play Quiz Ke Function ko Create Karne Wale Hai Jisme Ham Quiz Question Ko Display Kara Kar Usme Quiz Khel Sake Or Play Quiz Function ka data Json Format Hai Wo Bhi Mene Sabse Last Me Download Link Me De Rakha Hai |

user = []

def play():
	print("\n==========QUIZ START==========")
	score = 0
	with open("assets/questions.json", 'r+') as f:
		j = json.load(f)

		for i in range(10):
			no_of_questions = len(j)
			ch = random.randint(0, no_of_questions-1)
			print(f'\nQ{i+1} {j[ch]["question"]}\n')
			for option in j[ch]["options"]:
				print(option)
			answer = input("\nEnter your answer: ")
			if j[ch]["answer"][0] == answer[0].upper():
				print("\nYou are correct")
				score+=1
			else:
				print("\nYou are incorrect")
			del j[ch]
		print(f'\nFINAL SCORE: {score}')

Upper Diye Gaye Code Me Hamne Score Ko Bhi Add Kar Rahe Hai Or Fir Use Print Kara Rhe Hai |

Step 3 :- Ab Ham Quiz Me Add Question Ka Function Create Karne Wale Hai Or Fir Usme Ham Ek Condition Laga Ne Wale Hai | Usme Condtion Ye Hogi Ki Keval Admin Hi Question Ko Add Kar Sakta Hai |

def quizQuestions():
	if len(user) == 0:
		print("You must first login before adding questions.")
	elif len(user) == 2:
		if user[1] == "ADMIN":
			print('\n==========ADD QUESTIONS==========\n')
			ques = input("Enter the question that you want to add:\n")
			opt = []
			print("Enter the 4 options with character initials (A, B, C, D)")
			for _ in range(4):
				opt.append(input())
			ans = input("Enter the answer:\n")
			with open("assets/questions.json", 'r+') as f:
				questions = json.load(f)
				dic = {"question": ques, "options": opt, "answer": ans}
				questions.append(dic)
				f.seek(0)
				json.dump(questions, f)
				f.truncate()
				print("Question successfully added.")		
		else:
			print("You don't have access to adding questions. Only admins are allowed to add questions.")

Upper Diye Gaye Code Me Hamne Admin Panel Create Kiya Hai Wo bhi Quiz Question Add Karne Wala |

Python Quiz App Source Code

Step 4 :- Ham Ab Create User Ka Panel Create Karne Wale Hai Jo Ki User Aapna Account Create Karke Quiz Khel Sakta Hai Or Usme Aapna Score Dekh Sakta Hai |

def loginAccount():
	print('\n==========LOGIN PANEL==========')
	username = input("USERNAME: ")
	password = getpass.getpass(prompt= 'PASSWORD: ')
	with open('assets/user_accounts.json', 'r') as user_accounts:
		users = json.load(user_accounts)
	if username not in users.keys():
		print("An account of that name doesn't exist.\nPlease create an account first.")
	elif username in users.keys():
		if users[username][0] != password:
			print("Your password is incorrect.\nPlease enter the correct password and try again.")
		elif users[username][0] == password:
			print("You have successfully logged in.\n")
			user.append(username)
			user.append(users[username][1])

Aap Upper Diye Code Ko Dekh Sakte Hai Isme Hamne User Create System Create Kiya Hai |

Step 5 :- Ab Ham Log Out Function Ko Create Karne Wale Hai Matlab Jab User Login Karega To Wo Jarur Logout Bhi Karega |

def logout():
	global user
	if len(user) == 0:
		print("You are already logged out.")
	else:
		user = []
		print("You have been logged out successfully.")

Upper Dekh Sakte Hai Hamne Logout Function Create Kiya Hai |

Step 6 :- Ab Ham Game Rules Function Create Karne Wale Hai | matlab Agar User Ko Quiz Game Khelna Nhi Bhi Aata Hai to wo Game Rules Dekh kar Understand Kar Sakta Hai |

def rules():
	print('''\n==========RULES==========
1. Each round consists of 10 random questions. To answer, you must press A/B/C/D (case-insensitive).
Your final score will be given at the end.
2. Each question consists of 1 point. There's no negative point for wrong answers.
3. You can create an account from ACCOUNT CREATION panel.
4. You can login using the LOGIN PANEL. Currently, the program can only login and not do anything more.
	''')

Upper Diye Gaye Code me Hamne Rules Function Banaya Hai |

Step 7 :- Ab Ham About Function Create Karne Wale Hai Jisme Ham Aapna Credit Add Karenge |

def about():
	print('''\n==========ABOUT US==========
This project has been created by Danish Ali.''')

Python Quiz App Project

Step 8 :- Ab Ham Choice System Banane Wale hai Jisme Ham User Se Choice Input Karayenge Or Uske Hisab Se Output Dene Hai |

if __name__ == "__main__":
	choice = 1
	while choice != 7:
		print('\n=========WELCOME TO QUIZ MASTER==========')
		print('-----------------------------------------')
		print('1. PLAY QUIZ')
		print('2. ADD QUIZ QUESTIONS')
		print('3. CREATE AN ACCOUNT')
		print('4. LOGIN PANEL')
		print('5. LOGOUT PANEL')
		print('6. SEE INSTRUCTIONS ON HOW TO PLAY THE GAME')
		print('7. EXIT')
		print('8. ABOUT US')
		choice = int(input('ENTER YOUR CHOICE: '))
		if choice == 1:
			play()
		elif choice == 2:
			quizQuestions()
		elif choice == 3:
			createAccount()
		elif choice == 4:
			loginAccount()
		elif choice == 5:
			logout()
		elif choice == 6:
			rules()
		elif choice == 7:
			break
		elif choice == 8:
			about()
		else:
			print('WRONG INPUT. ENTER THE CHOICE AGAIN')

Aap Upper Diye Gaye Code Ko Dekh Sakte Hai Isme Hamne Choice System Create Kiya Hai |

Ab Ham Sare Code Ko Ek Sath Mila Kar Run Karne Wale Hai Or Usme Ham Uski Json File And Other File Bhi Add Karne Wale Hai |

Full Program Example :

import json
import random
import getpass

user = []

def play():
	print("\n==========QUIZ START==========")
	score = 0
	with open("assets/questions.json", 'r+') as f:
		j = json.load(f)
		for i in range(10):
			no_of_questions = len(j)
			ch = random.randint(0, no_of_questions-1)
			print(f'\nQ{i+1} {j[ch]["question"]}\n')
			for option in j[ch]["options"]:
				print(option)
			answer = input("\nEnter your answer: ")
			if j[ch]["answer"][0] == answer[0].upper():
				print("\nYou are correct")
				score+=1
			else:
				print("\nYou are incorrect")
			del j[ch]
		print(f'\nFINAL SCORE: {score}')

def quizQuestions():
	if len(user) == 0:
		print("You must first login before adding questions.")
	elif len(user) == 2:
		if user[1] == "ADMIN":
			print('\n==========ADD QUESTIONS==========\n')
			ques = input("Enter the question that you want to add:\n")
			opt = []
			print("Enter the 4 options with character initials (A, B, C, D)")
			for _ in range(4):
				opt.append(input())
			ans = input("Enter the answer:\n")
			with open("assets/questions.json", 'r+') as f:
				questions = json.load(f)
				dic = {"question": ques, "options": opt, "answer": ans}
				questions.append(dic)
				f.seek(0)
				json.dump(questions, f)
				f.truncate()
				print("Question successfully added.")		
		else:
			print("You don't have access to adding questions. Only admins are allowed to add questions.")


def createAccount():
	print("\n==========CREATE ACCOUNT==========")
	username = input("Enter your USERNAME: ")
	password = getpass.getpass(prompt= 'Enter your PASSWORD: ')
	with open('assets/user_accounts.json', 'r+') as user_accounts:
		users = json.load(user_accounts)
		if username in users.keys():
			print("An account of this Username already exists.\nPlease enter the login panel.")
		else:
			users[username] = [password, "PLAYER"]
			user_accounts.seek(0)
			json.dump(users, user_accounts)
			user_accounts.truncate()
			print("Account created successfully!")

def loginAccount():
	print('\n==========LOGIN PANEL==========')
	username = input("USERNAME: ")
	password = getpass.getpass(prompt= 'PASSWORD: ')
	with open('assets/user_accounts.json', 'r') as user_accounts:
		users = json.load(user_accounts)
	if username not in users.keys():
		print("An account of that name doesn't exist.\nPlease create an account first.")
	elif username in users.keys():
		if users[username][0] != password:
			print("Your password is incorrect.\nPlease enter the correct password and try again.")
		elif users[username][0] == password:
			print("You have successfully logged in.\n")
			user.append(username)
			user.append(users[username][1])

def logout():
	global user
	if len(user) == 0:
		print("You are already logged out.")
	else:
		user = []
		print("You have been logged out successfully.")

def rules():
	print('''\n==========RULES==========
1. Each round consists of 10 random questions. To answer, you must press A/B/C/D (case-insensitive).
Your final score will be given at the end.
2. Each question consists of 1 point. There's no negative point for wrong answers.
3. You can create an account from ACCOUNT CREATION panel.
4. You can login using the LOGIN PANEL. Currently, the program can only login and not do anything more.
	''')

def about():
	print('''\n==========ABOUT US==========
This project has been created by Danish Ali.''')

if __name__ == "__main__":
	choice = 1
	while choice != 7:
		print('\n=========WELCOME TO QUIZ MASTER==========')
		print('-----------------------------------------')
		print('1. PLAY QUIZ')
		print('2. ADD QUIZ QUESTIONS')
		print('3. CREATE AN ACCOUNT')
		print('4. LOGIN PANEL')
		print('5. LOGOUT PANEL')
		print('6. SEE INSTRUCTIONS ON HOW TO PLAY THE GAME')
		print('7. EXIT')
		print('8. ABOUT US')
		choice = int(input('ENTER YOUR CHOICE: '))
		if choice == 1:
			play()
		elif choice == 2:
			quizQuestions()
		elif choice == 3:
			createAccount()
		elif choice == 4:
			loginAccount()
		elif choice == 5:
			logout()
		elif choice == 6:
			rules()
		elif choice == 7:
			break
		elif choice == 8:
			about()
		else:
			print('WRONG INPUT. ENTER THE CHOICE AGAIN')

Output :

Python Quiz App Download Link

Final Code With File Folder :- Python Quiz App Project

Also Read This Python Project Post :-

Danish Ali

I Am a Cyber Security Student & I have Skills C, C++ ,Python, HTML,CSS, Computer & Advance Hacking & Blogger & YouTuber.

Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons