Quote:
Why the elif condition throws expected expression error in Python?
The answer is an indentation problem!
In Python, indentation is part of the language structure.
import json
print("Manage Employee Detail: ")
print("(a) for Add")
print("(u) for Update")
print("(d) for Delete")
Choice = (input("Enter Your choice: "))
if (Choice=="a") :
emp_dic =[{
"name" : input("Enter employee name : "),
"emp_id" : "2022-001",
"city" : input ("Enter city : "),
"experience" : int(input("Enter experience :")),
"ctc" : int(input("Enter CTC : ")),
"age" : int(input("Enter age : ")),
"contact" : int(input("Enter contact : "))
}]
with open ("emp.json","r") as file:
dic=json.load(file)
dic.append(emp_dic)
with open("emp.json","w") as file:
json.dump(dic, file , indent=4)
print(dic)
elif Choice=="u" :
it gives
if (Choice=="a") :
emp_dic =[{
"name" : input("Enter employee name : "),
"emp_id" : "2022-001",
"city" : input ("Enter city : "),
"experience" : int(input("Enter experience :")),
"ctc" : int(input("Enter CTC : ")),
"age" : int(input("Enter age : ")),
"contact" : int(input("Enter contact : "))
}]
with open ("emp.json","r") as file:
dic=json.load(file)
dic.append(emp_dic)
with open("emp.json","w") as file:
json.dump(dic, file , indent=4)
print(dic)
elif Choice=="u" :
...