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 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...
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,...
Need this in java .Create a simple login screen in java That lets people sign in...
Need this in java .Create a simple login screen in java That lets people sign in to the emergency room. It needs to ask for name, social,and DOB. Once all the information is received it then display the info back to them if any info is is missing have the program prompt the user to re enter their information.
PYTHON PROGRAM Requirements: 1. Create an empty directory a variable named song_search 2. Repeatedly prompt the...
PYTHON PROGRAM Requirements: 1. Create an empty directory a variable named song_search 2. Repeatedly prompt the user to enter either the title of a song or enter nothing if they have no more songs to enter 3. For each song title entered by the user, split the song title into words by using the split function and splitting on a space. For each word from each song title, ensure the song_search dictionary has a entry with that word as the...
Write a simple javascript program using express and node.js to create a simple webpage that can...
Write a simple javascript program using express and node.js to create a simple webpage that can lead to other pages within the program. if possible, Comment everything out so I could understand how every things works.  But basically, server should be hosted on localhost:8000 and should have a simple starting page. Maybe a welcome message, with at least two "links" that goes to a "homepage" and then a "exit" page.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT