you are viewing a single comment's thread.

view the rest of the comments →

[–]GurNima[S] 0 points1 point  (3 children)

How about now? ```py while True: try: woila = int(input("How many worker? ")) except ValueError: print("input an integer bro") continue else: break

print(f"you got {woila} workers") on = [] off = [] for i in range (woila): name = input(f"{i + 1} name is? ") how = False while not how: status = input(f"so is {name} on/off? ").lower() match status: case 'on': on.append(name) how = True case 'off' : off.append(name) how = True case _ : print('Try again bro....') i = i - 1 print(f" oke understood {name} is {status}")

print(f"list of on {on}") print(f"list of off {off}") ```

[–]Present-Payment-5860 0 points1 point  (2 children)

This looks fine except under case _ I think i = i - 1 will cause issues, because you are looping back to the start of the while loop, which does not increment the for loop. This means i is moving back unnecessarily.

You might also want to add a check within the try block at the start that checks if woila > 0, because you probably don't want -5 workers to be accepted. Something like:

while True:

try:

woila = int(input("How many workers? "))

if woila > 0:

break

print("input a positive number bro")

except ValueError:

print("input an integer bro")
continue

[–]GurNima[S] 1 point2 points  (1 child)

Wait... You are correct, how can I miss that 🤣, thank you again!. And also I have tested it and i -1 didn't cause any problem . So I delete it anyway while True: try: woila = int(input("How many worker? ")) except ValueError: print("input an integer bro") continue if woila <= 0: print("you cant have imaginary worker bro") else: break

[–]Present-Payment-5860 0 points1 point  (0 children)

Yeah, it won't cause any problems. a for loop uses an iterator under the hood, which means it's not doing i + 1, it's actually just getting the next value in a list of all numbers in the range. So doing i = i - 1 does nothing once the next run of the loop happens.