Update second version(2.0).py

This commit is contained in:
Felipe M.B
2022-04-19 15:41:37 -03:00
committed by GitHub
parent 92034ba2a1
commit b283647502

View File

@@ -8,43 +8,49 @@ f4 = ["ap13", "ap14", "ap15", "ap16"]
building = [f1 , f2, f3, f4] building = [f1 , f2, f3, f4]
bombs = [] bombs = []
bq = random.randint(1,10) bq = int(input("How many bombs do you desire? "))
print("please answer the following with yes or no")
twoin1 = str(input("Do you want more then one bomb in an apartment? "))
twoin1 =twoin1.lower()
#I made it possible for the user to choose how many bombs he wants to be generated, and if he wants
#to have the possibility for there to be more then one bomb in an apartment
g = 1 g = 1
for g in range(bq): for g in range(bq):
a = random.randint(0,3) a = random.randint(0, 3)
b = random.randint(0,3) b = random.randint(0, 3)
bl = building[a][b] bl = building[a][b]
bombs.append(bl) bombs.append(bl)
bombs2 = set(dict.fromkeys(bombs))#I was testing with lists , then had to make a dictionary to remove duplicates, # I was testing with lists , then had to make a dictionary to remove duplicates,
# but for the next version i will use SETS # but for the next version i will use SETS
size = len(bombs2)
#print(bl, a, b, bq)
print(bombs)
print(bombs2)
reroll = [] reroll = []
while size != bq: if twoin1 == "no":
r = bq - size bombs2 = set(dict.fromkeys(bombs))
for g in range(r): size = len(bombs2)
c = random.randint(0,3) while size != bq:
d = random.randint(0,3) r = bq - size
bl2 = building[c][d] for g in range(r):
reroll.append(bl2) c = random.randint(0, 3)
reroll2 = set(reroll) d = random.randint(0, 3)
size2 = len(reroll2) bl2 = building[c][d]
sf = len(reroll2.intersection(bombs2)) reroll.append(bl2)
print(reroll, r, bq, size, sf) reroll2 = set(reroll)
if sf >= 1: size2 = len(reroll2)
reroll.clear() sf = len(reroll2.intersection(bombs2))
if size2 == r and sf == 0: print(reroll, r, bq, size, sf)
bombsf = bombs2.union(reroll2) if sf >= 1:
break reroll.clear()
else: if size2 == r and sf == 0:
continue bombsf = bombs2.union(reroll2)
break break
else:
continue
break
else:pass
#I was able to make this verification to work, thus my code can be true to the bomb quantity that is randomly generated, now i need to make the floor verification #I was able to make this verification to work, thus my code can be true to the bomb quantity that is randomly generated, now i need to make the floor verification
#and make it so the user determines how many bombs will be generated #and make it so the user determines how many bombs will be generated
exit() exit() #I will now star to program the next section of my challenge and i will upload it as a 3.0
#I put this exit() to do some testing so please ignore what comes in the next blocks of code since i am testing a way #I put this exit() to do some testing so please ignore what comes in the next blocks of code since i am testing a way
# to generate random bombs and avoid duplicates # to generate random bombs and avoid duplicates
#After achieving this i will make thhe user input so you may choose how many bombs you want, and use a bollean to #After achieving this i will make thhe user input so you may choose how many bombs you want, and use a bollean to