Note that there are some explanatory texts on larger screens.

plurals
  1. POimporting and exporting from csv files
    primarykey
    data
    text
    <p><img src="https://i.stack.imgur.com/JLcmi.png" alt="enter image description here">So I am trying to create a code which can search the data file:</p> <ol> <li>By surname to retrieve and display the details for a contact</li> <li>By date of birth to retrieve and display all contacts with a birthday in a particular month.</li> </ol> <p>Here is the code I have created:</p> <pre><code>def search(): option = input('Please select to search by \n1. Surname\n2. D.O.B\n') if option == '1': surname = input('Please enter surname: ') while not surname.isalpha(): surname = str(input('Please enter a valid surname: ')) Myfile = open('Address book.csv', 'rt') for line in Myfile: if ',' + str(surname) + ',' in line: print(line) else: print('No contacts found') elif option == '2': Validmonth = False while Validmonth == False: month = input('Please enter the birth month') if month &gt;='13' and month &lt;='0': print('Please enter a valid month') else: Validmonth = True Myfile = open ('Address book.csv', 'rt') for line in Myfile: if str(month) in line: print(line) else: print('No contacts found') else: print('Error, select a valid option') search() search() </code></pre> <p>I keep getting this result when I try the code:</p> <pre><code>Please select to search by 1. Surname 2. D.O.B 1 Please enter surname: Vickers No contacts found No contacts found No contacts found No contacts found No contacts found No contacts found No contacts found No contacts found </code></pre> <p>I want to know why? someone please help?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload