dimanche 9 septembre 2018

I am new to Python , got stuck in a simple if else condition

I am new to Python , got stuck in a simple if else condition below. If I dont use any else condition then code is working, but if I use else then if condition is not getting executed(control directly goes to else, even the if condition is true). Please correct me if i am doing anything wrong in if else condition below...

import xlrd

name= input("please enter your name : ")

eid=input("please enter your empid : ")

location of the excel file

loc="C:/Users/anirbanG/Desktop/Python/emp_details.xlsx"

Getting the excel location

workbook=xlrd.open_workbook(loc)

Getting the sheet need to be read

worksheet=workbook.sheet_by_name("Sheet1")

for rowidx in range (worksheet.nrows): row=worksheet.row(rowidx)

for colidx, cell in enumerate(row):
    if cell.value==eid:
        columnid=colidx
        rowid=rowidx

    else:
        print("pls enter a valid empid")
        exit()

newmail=worksheet.cell(rowid, columnid+2).value name=worksheet.cell(rowid, columnid+1).value

print("Your otp sent to :" +newmail )

Aucun commentaire:

Enregistrer un commentaire