A simple Python Program

A simple Python Program

A simple Python Program, in this article i will demonstrate how to write a simple program  using Python code.

About the sample Program

  1. The sample Program will have a list of the User Data Base and pass code
  2. The User is requested to enter the Pass code
  3. Then if the Pass code is correct
  4. The User will be ask to enter the Data
  5. If the Data is Correct , the Python Program will print out (“Data is correctly eneter ” ) through a Python Function

The Python Code

 


pins =["Brian":12345,"Ken":6789 ,"Lynn":abcd]

def find_in_file(user_data)
    myfile = open("data.txt")
	readData =myfile.read()
	myfile.close()
	
	if user_data in readData:
	    print("The data is Valid")
	else:
	    return "No Such data"
		
		
print("Please enter your Pass Code")
userInput = int(input())

if userInput in pins.values():
    print("Enter the data ")
	enterData = input()
    print(find_in_file(enterData))	
else:
    print("Incorrect Pass Code")
	for key in pins.key():
	       print(key)

 

Stepping through the Code

  1. First ,I created a list to store the keys and value eg : Brian is a Key and 1234 is a value
  2. Then i created a function to check the data inside the File “data.txtx”
  3. The Function is pass a Parameter ” user_data”
  4. The function will open the “data.txt” file and by using the .read() function it will read the File and save what it reads into readData
  5. close the File to save memory
  6. Then check the “Argument ” pass into the Parameter ” user_data” and check whether the Argument Value the User enter is in the “data.txt” file
  7. If yes, tell the User that the data he or she entered is correct
  8. Else , tell them the Data they have enter is incorrect
  9. Now we come to the User interaction Part
  10. first ask the User to enter the Pass code value
  11. Check whether the User has enter a correct pass code value by checking through it using” pins.value “
  12. If the User enter the Correct Pin code Value, ask the User to input the Data
  13. Call the Function “find_in_file() ” and pass in the argument the User enter into the Parameter and check whether the User has entered the correct data
  14. else if the User enter the incorrect pass code, prints out the keys that are available to notified the User

Check out Writing and Reading File using Python here

Leave a Reply

Your email address will not be published. Required fields are marked *

two × 1 =