Function doc type and more in python

 



def function1():
    """This is a average calculator function"""
    a =str(input("Enter first Number: "))
    b =str(input("Enter Second Number: "))
    x=((int(a)+int(b))/2)
    return x


# This is a doc string which is used to print the instructoins about the function
print(function1.__doc__)


def functioncal():
    val1 = int(input("Enter the first number: "))
    oper =str(input("Enter Artmtic Opertor: "))
    val2 = int(input("Enter the second number: "))

    mydict = {"+":val1+val2,"-":val1 -val2,"/":val1/val2,"*":val1*val2,}
    quiz_ans={"45*3":"45 * 3 = 555","56+9":"56 + 9 = 77","56/6":"56 / 6 =4"}

    user_input=str(val1)+str(oper)+str(val2)

    if  user_input in quiz_ans:
        print(quiz_ans[user_input])
    elif oper in mydict:
        print(val1 , oper , val2, "=" ,mydict[oper])
    else:
        print("In vaid entry")
        return val1,

w=functioncal()

print(w)

while True:
    l = str(input("if you want to try again enter Y if you don\'t want to try again type N"))
    if l==str("y"):
        print(functioncal())
        continue
    elif l == str("n"):
        break

Comments