Question

In: Computer Science

Create a program using python that provides a simple calculator: Requires a login with a prompt...

Create a program using python that provides a simple calculator:

Requires a login with a prompt for a username and a password prior to using the calculator

If username and password are incorrect, the program should re-prompt to re-enter correct username and password

Once logged in, the user should have access to the calculator and should have the ability for the following mathematical operators:

Addition Subtraction

Multiplication

Division

Square Root

PI

Exponents

Solutions

Expert Solution

# to use sqrt, pi  bulit in fucntion

import math

# fucntion to calculate addition

def addition(num1, num2):

    return num1 + num2

# fucntion to calculate subtraction

def subtraction(num1, num2):

    return num1 - num2

# fucntion to calculate multiplication

def multiplication(num1, num2):

    return num1 * num2

# fucntion to calculate division

def division(num1, num2):

    return num1/ num2

# fucntion to calculate square root

def squareRoot(num):

    return math.sqrt(num)

    

# fucntion return the value of PI

def pi():

    return math.pi

# fucntion to calculate exponent

def exponent(num):

    return math.exp(num)

# fucntion show to options to user

def options():

    print("------Calculator-----")

    print("1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Square Root\n6.PI\n7.Exponent")

    choice = int(input("Enter your choice: "))

    return choice

# fucntion to print the result

def printResult(result):

    print("Result: " + str(result))

# main fucntion

def main():

    username = input("Enter the username: ")

    password = input("Enter the password: ")

    # lets username is 'username' and password is 'password'

    # checking user name and password

    if username == 'username' and password == 'password':

        # getting user's choice

        choice = options()

        # checking user choice

        if choice == 1:

            num1 = float(input("Enter the first number: "))

            num2 = float(input("Enter the second number: "))

            result = addition(num1, num2)

            # printing the reslult

            printResult(result)

        elif choice == 2:

            num1 = float(input("Enter the first number: "))

            num2 = float(input("Enter the second number: "))

            result = subtraction(num1, num2)

            # printing the reslult

            printResult(result)

        elif choice == 3:

            num1 = float(input("Enter the first number: "))

            num2 = float(input("Enter the second number: "))

            result = multiplication(num1, num2)

            # printing the reslult

            printResult(result)

        elif choice == 4:

            num1 = float(input("Enter the first number: "))

            num2 = float(input("Enter the second number: "))

            result = division(num1, num2)

            # printing the reslult

            printResult(result)

        elif choice == 5:

            num = float(input("Enter the number: "))

            result = squareRoot(num)

            # printing the reslult

            printResult(result)

        elif choice == 6:

            print("Value of PI is: " + str(pi()))

        elif choice == 7:

            num = float(input("Enter the number: "))

            result = exponent(num)

            # printing the reslult

            printResult(result)

        else:

            print("Wrong option selected :(:( ")

    else:

        print("Incorrect username or password :(:( ")



if __name__ == "__main__":

    #  calling the main function

    main()



Note: Let me know if you have any doubt..


Related Solutions

create a program that will verify a user's login credentials. The program should prompt the user...
create a program that will verify a user's login credentials. The program should prompt the user to enter his/her username and password at the keyboard. Then it should read the data from a data file named "login.txt". The file "login.txt" will contain a list of 3 valid usernames and passwords to verify the login information supplied by a user.  If the username and password entered by the user matches one of the sets read from the file, the program should print...
Create a Linear Program solver using Matlab or Python. Prompt variable and constraint entry.
Create a Linear Program solver using Matlab or Python. Prompt variable and constraint entry.
Create a python program that will: prompt a user for a command Command get_data Level 1:...
Create a python program that will: prompt a user for a command Command get_data Level 1: Take one of the commands my_max my_min my_range my_sum mean median mode fib factorize prime Requirements: Your commands should be case-insensitive You should use python lists to store data You should NOT use built-in python math functions, or math libraries to compute these values Tips: Write one function that will convert a string with comma-separated numbers into a python list with the numbers. You...
using PDO, MYSQL, and Html, how can i create a simple registration and login form for...
using PDO, MYSQL, and Html, how can i create a simple registration and login form for cPanel?
Create a program named CmdLineCalc.java that works like a simple calculator. You'll run this program from...
Create a program named CmdLineCalc.java that works like a simple calculator. You'll run this program from the command line: $ java CmdLineCalc 1 + 2 3.0 $ java CmdLineCalc 1 - 2.5 -1.5 $ java CmdLineCalc 3 + 4 - 5 2.0 $ java CmdLineCalc 6.5 - 7 + 8 7.5 To keep it simple, your program only needs to support addition (+) and subtraction (-). You may assume that, starting with the first argument, every other argument will be...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store data...
Using Python, create a program that will act as a number convertor. This program will convert...
Using Python, create a program that will act as a number convertor. This program will convert an input decimal integer into binary and hexadecimal formats. a) Define a main function named numberconvertor(). Inside the main function, write all the logic of your code. [5% marks] b) Looping indefinitely (Hint: use infinite while loop), the program should give the user the 3 options given below and allow the user to select one among them. [15% marks] 1. converting a decimal number...
How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
python code Write a simple calculator: This program must have 9 functions: •main() Controls the flow...
python code Write a simple calculator: This program must have 9 functions: •main() Controls the flow of the program (calls the other modules) •userInput() Asks the user to enter two numbers •add() Accepts two numbers, returns the sum •subtract() Accepts two numbers, returns the difference of the first number minus the second number •multiply() Accepts two numbers, returns the product •divide() Accepts two numbers, returns the quotient of the first number divided by the second number •modulo() Accepts two numbers,...
Python Implement a program that starts by asking the user to enter a login id (i.e.,...
Python Implement a program that starts by asking the user to enter a login id (i.e., a string). The program then checks whether the id entered by the user is in the list ['joe', 'sue', 'hani', 'sophie'] of valid users. Depending on the outcome, an appropriate message should be printed. Regardless of the outcome, your function should print 'Done.' before terminating. Here is an example of a successful login: >>> Login: joe You are in! Done. And here is one...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT