Question

In: Computer Science

Writing python code: Can you do for me this. The question looks bellow Overview : As...

Writing python code: Can you do for me this.

The question looks bellow

Overview :

As a programmer, you have be asked by a good friend to create a program that will allow them to keep track of their personal expenses. They want to be able to enter their expenses for the month, store them in a file, and then have the ability to retrieve them later. However, your friend only wants certain people to have the ability to view his or her expenses, so they are requesting that you include some sort of login functionality. Instructions : For this challenge, you will start this application for your friend by concentrating on the login functionality. You will have a standard report in a text file where you will build login functionality to access. Below you will find the step by step instructions on how to develop this application.

1. Declaring Variables - You will start the application by declaring the following variables:

# username - initialized with an empty string to store the username entered by the user.

#password - initialized with an empty string to store the password entered by the user.

#repeat - initialized with the letter 'y' to control the looping of the program'

#passwordLength - intialized with the number 8 to validate password length ,

#Four flags set to false named hasAmpersand, hasValidLength, isValidUsername, and isValidPassword

2. Display the program header as shown in the images below

3. Your program must allow the program to repeat without re-displaying the program header.

4. You must obtain the username from the user then check to see if the username contains the @ symbol. If does, set the hasAmpersand flag to true and allow the program to continue. If it doesn't, alert the user that it is an invalid email and use the continue command to skip the rest of the code and repeat the program.

5. Obtain the user password and use a while loop to make sure that the user has entered a password greater than the number stored in the passwordLength variable. After the password has been validated to be greater than the stated password length, change the hasValidLength flag to true.

6. You will then use the hasAmpersand and hasValidLength flags to confirm whether or not to open the logins.txt file to confirm that this login information is present in the file. This is when you would change the appropriate isValid flags to state that they are in the file. (HINT: You can check first that the username is in the file, if not, then there is no need to check for the password.) If the username is not in the file, use the break statement to end the program as shown below.

7. The report stored in the PersonalExpense.txt file should only be display if both the username and password is correct.

8. The text files for this application are attached to the Dropbox. You may download and add them to your solution. Or feel free to create your own login and report pages. View comments (1)

Solutions

Expert Solution

CODE:

import csv

# dictionary to hold the login information

dict_login={}

# file reader to read the login.txt

reader = csv.reader(open('login.txt'))

for row in reader:

    key = row[0]

    if key in dict_login:

        # implement your duplicate row handling here

        pass

    dict_login[key] = row[1]

# initial instruction

print('Please enter the username, with email id')

print('Please enter the password, having length greater than 8')

# method to take inputs and perform business logic

def takeInputs():

    cntr=0

    # continue till user explicitly exits

    while(True):

        cntr+=1

        # if visiting second time

        if cntr>1:

            print("Want to login again?, press y to continue")

            y=input()

            if y.strip().lower()!="y":

                break

        username=input("Please enter username").strip()

        password=input("Please enter password").strip()

        hasAmpersand=False

        hasValidLength=False

        isValidUsername=False

        isValidPassword=False

        #if username contains @

        if "@" in username:

            hasAmpersand=True

            # if passowrd length is greter than 8

            if len(password)>=8:

                hasValidLength=True

                # if username is present in the login dictionary

                if username in dict_login:

                    isValidUsername=True

                    # if password mathces

                    if password==dict_login[username]:

                        isValidPassword=True

                        # logic to display  the expense report

                        filehandle = open("PersonalExpense.txt", 'r')

                        while True:

                            # read a single line

                            line = filehandle.readline()

                            if not line:

                                break

                            print(line)

                        filehandle.close()

                    # failed condition to password

                    else:

                        print("Supplied password was wrong")

                        continue

                # failed username presence

                else:

                    print("Provided username is not present in our records")

                    continue

            # failed pasword length criteria

            else:

                print("password length criteria not met, flow will restart")

                continue

        # failed username presence

        else:

            print("Not a valid username, flow will restart")

            continue

takeInputs()

FILES:

login.text

username,password
[email protected],ertyghyui
[email protected],machine54
[email protected],ertyghyui
[email protected],machine54
[email protected],ertyghyui
[email protected],machine54
[email protected],ertyghyui
[email protected],machine54

PersonalExpense.txt:

Some random information related to the expense

SNIPPET:

RESULT:


Related Solutions

In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
fix this code in python and show me the output. do not change the code import...
fix this code in python and show me the output. do not change the code import random #variables and constants MAX_ROLLS = 5 MAX_DICE_VAL = 6 #declare a list of roll types ROLLS_TYPES = [ "Junk" , "Pair" , "3 of a kind" , "5 of a kind" ] #set this to the value MAX_ROLLS pdice = [0,0,0,0,0] cdice = [0,0,0,0,0] #set this to the value MAX_DICE_VAL pdice = [0,0,0,0,0,0] cdice = [0,0,0,0,0,0] #INPUT - get the dice rolls i...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This assignment will give you experience on the use of the while loop and the for loop. You will use both selection (if) and repetition (while, for) in this assignment. Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number...
can you please create the code program in PYTHON for me. i want to create array...
can you please create the code program in PYTHON for me. i want to create array matrix Nx1 (N is multiple of 4 and start from 16), and matrix has the value of elements like this: if N = 16, matrix is [ 4 4 4 4 -4 -4 -4 -4 4 4 4 4 -4 -4 -4 -4] if N = 64, matrix is [8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8...
in python You will be writing a program that can be used to sum up and...
in python You will be writing a program that can be used to sum up and report lab scores. Your program must allow a user to enter points values for the four parts of the problem solving process (0-5 points for each step), the code (0-20 points), and 3 partner ratings (0-10) points each. It should sum the points for each problem-solving step, the code, and the average of the three partner ratings and print out a string reporting the...
**To Be Written in Python for Beginners** Overview Do you know what an alternade is? Of...
**To Be Written in Python for Beginners** Overview Do you know what an alternade is? Of course you don’t, no one does! According to Wikipedia, an alternade: “is a word in which its letters, taken alternatively in a strict sequence, and used in the same order as the original word, make up at least two other words. All letters must be used, but the smaller words are not necessarily of the same length. For example, a word with seven letters...
Can someone please explain to me why "return 1" in this Python code returns the factorial...
Can someone please explain to me why "return 1" in this Python code returns the factorial of a given number? I understand recursion, but I do not understand why factorial(5) returns 120 when it clearly says to return 1. def factorial(n): if n == 0: return 1 else: return n * factorial(n-1)
Can someone tell me what is wrong with this code? Python pong game using graphics.py When...
Can someone tell me what is wrong with this code? Python pong game using graphics.py When the ball moves the paddles don't move and when the paddles move the ball doesn't move. from graphics import * import time, random def racket1_up(racket1):    racket1.move(0,20)        def racket1_down(racket1):    racket1.move(0,-20)   def racket2_up(racket2):    racket2.move(0,20)   def racket2_down(racket2):    racket2.move(0,-20)   def bounceInBox(shape, dx, dy, xLow, xHigh, yLow, yHigh):     delay = .005     for i in range(600):         shape.move(dx, dy)         center = shape.getCenter()         x = center.getX()         y = center.getY()         if x...
This is Python coding question, and topic is loop Can anyone help me figuring these out?...
This is Python coding question, and topic is loop Can anyone help me figuring these out? (Please do not use build in function) Thanks. 1. Write a program that prints your name 100 times to the screen. 2. Write a program that takes a string s and an integer n as parameters and prints the string s a total of in n times(once per line) 3. Write a for loop that prints all the integers from 3141 to 5926, skipping...
Can you explain to me what the characteristics of goal writing and setting as related to...
Can you explain to me what the characteristics of goal writing and setting as related to strategic planning for health IT?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT