Oct-05-2017, 03:38 PM
So I am new to coding and have been instructed to create a program that stores information in a database and can retrieve it at the users command. However, I am having trouble reading the database.
"If you would like to view your record, type 'yes' or type 'no' to display message:no
What information would you like to view?
Please select: Age, Gender or Fullname. If you would like to view all your information, type 'all'"
And here is my complete code, incase any of the errors are hidden within a section I did not include:
Thank you, I hope I can reach a solution to please my teacher as she described my work as a "Disappointing effort"
question = input("Would you like to view or create a new record? \n A: Create a new record \n B: View a record ") if question=="B": f = open("Database (2).txt","r") file_contents=f.read() print(file_contents) f.close()When the user selects to retrieve a record, it simply continues as if "A" has been selected, where the program asks the user for information. Here is "A"
if question=="A" or "a": firstname = input("Please enter your first name: ") surname = input("Welcome, please enter your surname: ") year = int(input("Please enter the year you were born: ")) month = input("Please enter the month you were born: ") day = input("Please enter the day you were born: ") gender = input("Please enter your gender:")I am also experiencing an error when the program asks whether you would like to view the information you just entered. For example, when stating that you would not like to view the information, it would continue to ask what information you would like to see. Here is the section of the code:
option=input("If you would like to view your record, type 'yes' or type 'no' to display message") if option=="yes" or "Yes": print("What information would you like to view?") info=input("Please select: Age, Gender or Fullname. If you would like to view all your information, type 'all'") if info == "Age": print("You are",age) elif info == "Gender": print("You are",gender) elif info == "Fullname": print("Your name is",fullname) else: print("You are",age) print("You are",gender) print("Your name is",fullname) if option =="no" or "No": print("Thank you for using our database")Here is what I mean (Taken from when the program is running)
"If you would like to view your record, type 'yes' or type 'no' to display message:no
What information would you like to view?
Please select: Age, Gender or Fullname. If you would like to view all your information, type 'all'"
And here is my complete code, incase any of the errors are hidden within a section I did not include:
import csv print("Please enter your password that has been e-mailed to you:") password = "stone" entry=input() #while loop while entry != password: print("Password incorrect") entry=input("Please input your password") if entry == password: print("Your password is correct") question = input("Would you like to view or create a new record? \n A: Create a new record \n B: View a record ") if question=="B": f = open("Database (2).txt","r") file_contents=f.read() print(file_contents) f.close() if question=="A" or "a": firstname = input("Please enter your first name: ") surname = input("Welcome, please enter your surname: ") year = int(input("Please enter the year you were born: ")) month = input("Please enter the month you were born: ") day = input("Please enter the day you were born: ") gender = input("Please enter your gender:") fullname=firstname + surname print("Your name is",fullname) age=2017 - year print("You are",age,"years old") print("You are",gender) with open("Database(2).txt", "a") as file: filewriter=csv.writer(file) filewriter.writerow([firstname,surname,age,gender]) option=input("If you would like to view your record, type 'yes' or type 'no' to display message") if option=="yes" or "Yes": print("What information would you like to view?") info=input("Please select: Age, Gender or Fullname. If you would like to view all your information, type 'all'") if info == "Age": print("You are",age) elif info == "Gender": print("You are",gender) elif info == "Fullname": print("Your name is",fullname) else: print("You are",age) print("You are",gender) print("Your name is",fullname) if option =="no" or "No": print("Thank you for using our database")If possible, could someone please teach me how to add a limit to the number of times an incorrect password can be entered please?
Thank you, I hope I can reach a solution to please my teacher as she described my work as a "Disappointing effort"
