Program to create a test using time ,random,pyttsx3 library in python programming.

Program to create a test using time ,random,pyttsx3 library in python programming:

import pyttsx3
import time
import random
psw=random.randint(1,1000)
a=len(str(psw))
print("Password :",psw)
q=pyttsx3.init()
for x in range(1,a+1):
    print("*",end="")
print("  ")
q.say("Sir,If you wants to use this program enter the correct password as given above.")
q.runAndWait()
print("Re-enter your password :")
pwsn=int(input())
if(psw==pwsn):
    q.say("welcome to my program")
    time.sleep(1)
    q.say("My website  is www.a three programming.blogspot.com")
    print("**********************Welcome************************")
    print("                         //www.a3programming.blogspot.com")
    print("                                           Test(Multiple choice questions)                                            ")
    q.say("Read instruction carefully.")
    print("Read instruction carefully.")
    time.sleep(1)
    q.say("You got 5 marks for each correct answer and -1 leave for each incorrect answer. ")
    print("*You got 5 marks for each correct answer and -1 leave for each incorrect answer. ")
    time.sleep(1)
    q.say("Quilfying marks is up to 60% ")
    print("Quilfying marks is up to 60% ")
    time.sleep(1)
    q.say("Questions are following :-")
    print("Questions are following :-")
    q.runAndWait()
    def a():
        global i
        i=0
        q.say("Red fort was built in year 1648 by?")
        print("Red fort was built in year 1648 by?")
        q.say("Press one Akbar,Press two Shahjahan,Press three  Aurangzeb,Press four Hamayun")
        print("Press 1: Akbar,Press 2: Shahjahan,Press 3:  Aurangzeb,Press 4: Hamayun")
        q.runAndWait()
        color=int(input())
        if(color==2):
            i=i+5
            q.say("Correct Answer.")
            q.runAndWait()
            print("Correct Answer.")
            return i
        else:
            i=i-1
            q.say("Wrong Answer")
            print("Wrong Answer.")
            q.runAndWait()
            return i
    def b():
        global j
        j=0
        q.say("Rashtrapati Bhawan in Delhi has")
        print("Rashtrapati Bhawan in Delhi has?")
        q.say("press one 340 rooms press two 240 rooms press three 140 rooms press 40 rooms")
        print("Press 1: 340 rooms,Press 2: 240 rooms,Press 3:  140 rooms,,Press 4: 40 rooms")
        q.runAndWait()
        color=int(input())
        if(color==1):
            j=j+5
            q.say("Correct Answer.")
            print("Correct Answer.")
            q.runAndWait()
            return j
        else:
            j=j-1
            q.say("Wrong Answer")
            print("Wrong Answer.")
            return j
    def c():
        global v
        v=0
        q.say("Mahatma gandhi give the slogen do or die in the movement")
        print("Mahatma Gandhi gave the slogan 'Do or Die' in the movement?")
        q.say("Press one Dandi March,Press two Khilafat movement,Press two Quit India movement,press four Non-corporation movement")
        print("Press 1: Dandi March,Press 2: Khilafat movement,Press 3: Quit India movement,Press 4: Non-corporation movement.")
        q.runAndWait()
        color=int(input())
        if(color==3):
            v=v+5
            q.say("Correct Answer.")
            print("Correct Answer.")
            q.runAndWait()
            return v
        else:
            v=v-1
            q.say("Wrong Answer")
            print("Wrong Answer.")
            q.runAndWait()
            return v
    def d():
        global u
        u=0
        q.say("Name the plant that is used in ayurveda for improving memory?")
        print("Name the plant that is used in ayurveda for improving memory?")
        q.say("Press one Amala,Press two Brahmi,Press three  Tulsi,Press four Vasaka.")
        print("Press 1: Amla,Press 2: Brahmi,Press 3:  Tulsi,Press 4: Vasaka.")
        q.runAndWait()
        color=int(input())
        if(color==2):
            u=u+5
            q.say("Correct Answer.")
            print("Correct Answer.")
            q.runAndWait()
            return u
        else:
            u=u-1
            q.say("wrong answer")
            print("Wrong Answer.")
            q.runAndWait()
            return u
    def e():
        global s
        s=0
        q.say("The forth state of matter is known as?")
        print("The forth state of matter is known as?")
        q.say("Press one Gas,Press two Vapour,Press three  Plasma,Press four Electrons.")
        print("Press 1: Gas,Press 2 :Vapour,Press 3:  Plasma,Press 4: Electrons.")
        q.runAndWait()
        color=int(input())
        if(color==3):
            s=s+5
            q.say("Correct Answer.")
            print("Correct Answer.")
            q.runAndWait()
            return s
        else:
            s=s-1
            q.say("wrong answer")
            print("Wrong Answer.")
            q.runAndWait()
            return s
    num=random.randint(1,6)
    if(num==1):
        a()
        b()
        c()
        d()
        e()
        print("Total maks is:",(i+j+v+u+s))
    elif(num==2):
        b()
        a()
        c()
        e()
        d()
        print("Total maks is:",(i+j+v+u+s))
    elif(num==3):
        d()
        b()
        e()
        c()
        a()
        print("Total maks is:",(i+j+v+u+s))
    elif(num==4):
        e()
        b()
        d()
        c()
        a()

    else:
        b()
        e()
        c()
        d()
        a()
        print("Total maks is:",(i+j+v+u+s))
    per=lambda i,j,v,u,s:(i+j+v+u+s)*(100/25)
    print("Percent :",per(i,j,v,u,s),"%")
    res=per(i,j,v,u,s)
    if(res>=60.0):
        q.say("Successfully you qualify this test ,sir")
        q.say("oh ye ye oh ye oh ye")
        print("Successful !,you qualify this test.")
        q.runAndWait()
    else:
        q.say("ha ha ha ha ha ha ha,you fail")
        print("Oh!,you fail try again later!")
        q.runAndWait()
else:
    q.say("Sir you enter incorrect password ")
    q.say("Sir,please enter valid password")
    q.say("try again later!")
    q.runAndWait()
    print("Sir,please enter valid password")
    print("try again later!")
    exit()

Expected output is:

Post a Comment

0 Comments