I am just trying to figure out what the issue is with my output on this simple name generating project in Python. The program work just fine and accepts all the inputs, but when it prints the result I get duplicates of certain names when I simply want a name printed for each int in my amount variable. Below is a copy of the code...
import random
import string
#Welcome to program
print("Welcome to the EC2 unique name generator")
print("")
depts = ['marketing', 'accounting', 'finops']
ec2list = []
#Department input and check
department = input("Please state your department (Marketing, Accounting, FinOps): ").lower()
#If check department unsuccessful print unauthorized message
if (department not in depts):
print ("You are not authorized to use this EC2 name generator. ")
else: #if department check successful take amount
print("")
amount = int(input("Enter the amount of EC2 instances: "))
#instance name creation. created instance, randomnum, randomchar, ec2name variables
for instance in range(0, amount):
randomnum = random.randint(100, 999)
randomchar = ''.join(random.choices(string.ascii_letters, k=5))
ec2name = "{}_{}{}{}".format(department, randomnum, randomchar, instance)
ec2list.append(ec2name)
#print formatted list
print("\n".join(ec2list))
Below is an example of my output when I ask for the names of 5 instances. feel like this is a simple fix going over my head. Thanks in advance.