I have a program for enumerating the users with administrative privileges on Windows. I also want to display the number of accounts found which is stored in a variable called num_administrator
.
I have the following piece of code:
if num_administrators > 1:
print("[*] {} accounts with administrative privileges found:\n".format(num_administrators))
show_admins()
elif num_administrators == 1:
print("[*] {} account with administrative privileges found:\n".format(num_administrators))
show_admins()
else:
print("[*] No accounts with administrative privileges found.\n")
If there aren't admins I would like to print [*] No accounts with administrative privileges found.
If there is 1 or more admins the message to display is almost the same, the only difference is the display of account
or accounts
according to the number. It's only a matter of 1 letter (s
).
Can I achieve the conditional print just by using a unique statement or anyway in a simpler way?
Is it possible to print something like:
print("[*] {} account".format(num_administrators) + if num_administrators > 1 "s" + "with administrative privileges found:\n")
Don't mind my code above, I don't know the syntax if what I'm doing makes sense, it's just to give you an idea of what I'm thinking and you can tell me if it's doable or not.
Besides I'm calling the function show_admins()
3 times (for printing the admin accounts) but actually I can call it just once at the end I guess.