0
import csv

samsung = ['samsung','s1','s2','s3','s4','s5','s6','s7','galaxy']
iphone = ['iphone']
problemTypes = []
solution = []
instruction = []

def solve():
    def foundProblem():
        for queryPart in whatProblem:
            for problem in problemTypes:
                if queryPart == problem:
                    return True
    solved = False
    readCSV = csv.reader(csvfile, delimiter = ',') 
    for row in readCSV:
        solution = row[0] 
        problemTypes = row[1].split()
        instruction = row[2]
        if foundProblem():
            print('The solution is to '+solution)
            print(instruction)
            solved = True
    if solved == False:
        print('Solution not found.\nPlease contact your supplier')

whatProblem = str(input('What seems to be the issue with your smartphone?\n')).lower().split()
version = input('What type of phone do you have?\n').lower().split()
if version == iphone:
    with open('iPhone.csv') as csvfile:
        solve()
elif version in samsung:
    with open('samsung.csv') as csvfile:
        solve()
else:
    print('Phone not supported')

This is an attempt at creating a trouble shooter using multiple csv files however I am met with the problem of the samsung part. It seems that it cannot notice that the input is actually part of the samsung variable. I am new here so if I have formatted this wrong please notify me and if the solution is extremely simple please know I am new to coding.

3 Answers3

0

Try at least to change this line:

version = input('What type of phone do you have?\n').lower().split()

into:

version = input('What type of phone do you have?\n').lower().split()[0]

But reading input you currently force the user to enter 'samsung' which is not the most accessible approach. Keep on learning and trying and it will work out fine!

Dilettant
  • 3,267
  • 3
  • 29
  • 29
0

It's not entirely clear which bit you're having a problem with, but this extract looks wrong:

with open('iPhone.csv') as csvfile:
    solve()

You probably intend to use csvfile within the block:

with open('iPhone.csv') as csvfile:
    solve(csvfile)

and to change the implementation of solve to accept csvfile as an argument. As it is, it looks like you're trying (and failing) to communicate via a global variable; even if that did work, it's a poor practice that leads to unmaintainable code!

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
0

I'm not sure exactly what your problem is either but maybe try this statement instead of your other elif statement:

  elif any(version in s for s in samsung):

Check if a Python list item contains a string inside another string

Community
  • 1
  • 1
nesooM
  • 1