everyone. I have a Python assignment that requires me to do the following:
- Download this CSV fileLinks to an external site of female Oscar winners (https://docs.google.com/document/d/1Bq2T4m7FhWVXEJlD_UGti0zrIaoRCxDfRBVPOZq89bI/edit?usp=sharing) and open it into a text editor on your computer
- Add a text file to your sandbox project named OscarWinnersFemales.txt
- Copy and paste several lines from the original file into your sandbox file. Make sure that you include the header.
- Write a Python program that does the following:
- Open the file and store the file object in a variable
- Read the entire contents line by line into a list and strip away the newline character at the end of each line
- Using list slicing, print lines 4 through 7 of your file
- Write code that will ask the user for an actress name and then search the list to see if it is in there. If it is it will display the record and if it is not it will display Sorry not found.
- Close the file
Below is the code I currently have. I've already completed the first three bullet points but I can't figure out how to implement a search function into the list. Could anyone help clarify it for me? Thanks.
f = open('OscarsWinnersFemales.txt')
f = ([x.strip("\n") for x in f.readlines()])
print(f[3:7])
Here's what I tried already but it just keeps returning failure:
def search_func():
actress = input("Enter an actress name: ")
for x in f:
if actress in f:
print("success")
else:
print("failure")
search_func()