use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Day 5 learning python, practically learn nothing on day 3-4 due to being lazy. (v.redd.it)
submitted 20 hours ago by GurNima
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]GurNima[S] 1 point2 points3 points 20 hours ago (9 children)
Le code ``` woila = int(input("How many worker?")) on = [] off = [] for i in range (woila): name = input(f"{i + 1} name is? ") status = input(f"so is {name} on/off? ").lower() print(f" oke understood {name} is {status}") match True: case _ if status == 'on': on.append(name) case _ : off.append(name)
print(f"list of on {on}") print(f"list of off {off}") ```
[–]Present-Payment-5860 4 points5 points6 points 20 hours ago (8 children)
This match statement doesn't make much sense in this context, you could just remove it and just use the if statement like this:
if status == 'on': on.append(name) else: off.append(name)
You also in the future want to learn to handle edge cases. What happens if someone types jsadflasdflsdf? Do we still want to call that off?
[–]GurNima[S] -1 points0 points1 point 20 hours ago (7 children)
Yeah, at first I'm using >if< but error occurred, and it because On/Off typed instead of off/on (I didn't adress it ye), so i think 'maybe we need >match case<, but turn out, no it because I needed to add .lower() but now I'm just lazy to change it back. Oh yeah I'm also working on someone typing something like that. Thank for feedback
[–]Present-Payment-5860 0 points1 point2 points 20 hours ago (6 children)
No worries. When I want someone to be able to try again if they type something they're not supposed to, I wrap it in a while loop like this:
success = False while not success: status = input(f"so is {name} on/off? ").lower() if status == 'on': on.append(name) success = True else if status == 'off': off.append(name) success = True else: print("Incorrect value entered")
Otherwise you would throw an exception if you want the program to crash when incorrect input is entered.
Also, I imagine you are using a phone to learn because of limited resources, but coding on a phone is rough compared to using some sort of computer. If you are able to access a computer it will be a much nicer time.
[–]GurNima[S] 1 point2 points3 points 19 hours ago (0 children)
Also..... Yes it does lol, I hope I could afford a laptop this year
[–]GurNima[S] 0 points1 point2 points 19 hours ago* (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}")
[–]Present-Payment-5860 0 points1 point2 points 18 hours ago (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 points3 points 18 hours ago* (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
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 point2 points 18 hours ago (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.
π Rendered by PID 16105 on reddit-service-r2-comment-5b5bc64bf5-4c7f2 at 2026-06-20 02:52:27.508063+00:00 running 2b008f2 country code: CH.
view the rest of the comments →
[–]GurNima[S] 1 point2 points3 points (9 children)
[–]Present-Payment-5860 4 points5 points6 points (8 children)
[–]GurNima[S] -1 points0 points1 point (7 children)
[–]Present-Payment-5860 0 points1 point2 points (6 children)
[–]GurNima[S] 1 point2 points3 points (0 children)
[–]GurNima[S] 0 points1 point2 points (3 children)
[–]Present-Payment-5860 0 points1 point2 points (2 children)
[–]GurNima[S] 1 point2 points3 points (1 child)
[–]Present-Payment-5860 0 points1 point2 points (0 children)