I have a code which takes a user's input which is supposed to be a first and last name. My code then takes that input and searches a csv for projects and hours that the input name is associated to. The problem I'm running into is if I misspell or don't capitalize the first letter of each name the code will not work. Is there a function or a way out there where if the user inputs the first 3 letters right or something similar the code will automatically assume the correct spelling and change the input accordingly? I'm a very novice coder so any help would be great.
Here's my code for reference:
import csv
# I've used full name to avoid duplicate first names in report
full_name = input('Enter your full name: ')
with open('Report1.csv') as csvfile:
hour_summation = {}
read_csv = csv.reader(csvfile, delimiter=',')
for row in read_csv:
if ' '.join((row[0], row[1])) == full_name.strip():
hour_summation[row[2]] = hour_summation.get(row[2], 0) + int(float(row[3]))
print('This is {} full hours report:'.format(full_name))
for k, v in hour_summation.items():
print(k + ': ' + str(v) + ' hours')
You can use str.lower
on both the user input and the value from the csv to ignore case.
You can use str.startswith
to match the user input against the beginning of a value from the csv. You could also use in
to detemrine if the user input is in a value from the csv.