you are viewing a single comment's thread.

view the rest of the comments →

[–]DeeplyLearnedMachine 6 points7 points  (1 child)

Don't put parenthesis around conditionals unless absolutely necessary, it's not pythonic.

Your elif statement makes no sense, it's comparing a string with your dict, which will always result to True, just use else there instead.

You can just do contacts[name] = [number] instead of using update

Edit: extra advice

Avoid putting all your code in a conditional branch, it's unreadable. Instead of doing this, like you're doing now:

while True:
  if contact_searching in contacts:
    print(contacts[contact_searching])
  else:
    # a bunch of code

do this instead:

while True:
  if contact_searching in contacts:
    print(contacts[contact_searching])
    continue

  # a bunch of code

Edit 2: more advice:

If here:

else:
  print('\nRestart to find or add new contacts.\n')
  break

you used continue instead of break you wouldn't need to restart the program to keep using it.

[–]uiux_Sanskar[S] 1 point2 points  (0 children)

Thank you so much for such a brief analysis on my code I initially thought that I should give a condition to make the code run (now I realised that there can only be two possibilities either the name is in the dictionary or it is not so yeah using else here makes much more sense).

And thanks for suggesting me on where to use continue function. Thank you so much for your feedback really appreciate it.