mardi 31 décembre 2019

Python - Dictionary - If loop variable not changing

''' Created on Dec 24, 2019

Project is about to convert short forms into long description and read from csv file example: user enters LOL and then it should response 'Laugh of Laughter' Expectation: Till the time time user enter wrong keyword computer keep on asking to enter short form and system answers it's long description from CSV file I considered each row of CSV file as dictionary and broke down into keys and values Logice Used: - Used while so, that it keeps on asking until short coloumn didn't finds space, empty cell. But issue is after showing successfull first attempt comparision in IF loop is not happening because readitems['short' ] is not getting updated on each cycle

AlisonList.csv Values are: short,long lol,laugh of laughter u, you wid, with '''

import csv
from lib2to3.fixer_util import Newline
from pip._vendor.distlib.util import CSVReader
from _overlapped import NULL

READ = "r"
WRITE = 'w'
APPEND = 'a'

# Reading the CSV file and converted into Dictionary

with open ("AlisonList.csv", READ) as csv_file:
readlist = csv.DictReader(csv_file)

# Reading the short description and showing results

    for readitems in readlist:        
    readitems ['short'] == ' '        
    while readitems['short'] !='' :
    # Taking input of short description            
    smsLang = str(input("Enter SMS Language :  "))
    if smsLang == readitems['short']:
    print(readitems['short'], ("---Means---"), readitems['long'])
    else:
    break

Aucun commentaire:

Enregistrer un commentaire