Reputation: 23
Thanks in Advance! Please suggest the correct code. I used the below code but not able to access the empid entered by the user.
My Query is:
# Create Foll. Information in the Tuple (at least 5 Employees)
# 1. EmpId - Phone Numbers (One Employee can have Multiple Numbers )
# 2. Accept Empid from User. Display his Numbers only if he exists in the Database(Tuple). Display App. Message if not present```
## My Code
empdetail = (("101",1234587),("102",2588467,2798478),("103",2689822,123456),("104",28398466),("105",8998666))
empid = input("Enter Employee Id :")
for name in empdetail:
if empid in empdetail:
res = empdetail[i][i:]
print(str(res))
break
else:
print("Employee not present.")
break
print(empdetail)
Upvotes: 0
Views: 192
Reputation: 1141
I would transform that into a dictionary.
empdetail = (("101",1234587),("102",2588467,2798478),("103",2689822,123456),("104",28398466),("105",8998666))
empid = input("Enter Employee Id :")
emp_dict = {key: values for key, *values in empdetail}
if empid in emp_dict.keys():
print(*emp_dict[empid])
else:
print("Employee not present.")
Upvotes: 1
Reputation: 116
empdetail = (("101",1234587),("102",2588467,2798478),("103",2689822,123456),("104",28398466),("105",8998666))
empid = input("Enter Employee Id :")
for i in range(len(empdetail)):
if empid in empdetail[i]:
res = empdetail[i][0:]
print(str(res))
break
else:
print("Employee not present.")
print(empdetail)
Upvotes: 0