How to skip over a environment variable when iterating over them

Question:

this is my code:

import os

def main():
  g = input("What's the password?n")
  if g == os.environ['master-password']:
    for name, value in os.environ.items():
      if name == "master-password":
        break #obviously just ends the program
      else:  
        print("{0}: {1}".format(name, value))
      
main()

I want to skip the master password so it is not revealed.
The reason I want this is that I’m using replit

Asked By: hackerman

||

Answers:

Use continue instead of break to skip to the next iteration of the loop.

g = input("What's the password?n")
if g == os.environ["master-password"]:
    for name, value in os.environ.items():
        if name == "master-password":
            continue
        print(f"{name}: {value}")
Answered By: AKX

Replace break with pass.

g = input("What's the password?n")
if g == os.environ["master-password"]:
    for name, value in os.environ.items():
        if name == "master-password":
            pass
        else:
            print(f"{name}: {value}")
Answered By: codester_09
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.