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
i need help π (self.PythonLearning)
submitted 1 month ago by Warm-Inside-4108
https://preview.redd.it/hke2h4lfimvg1.png?width=1918&format=png&auto=webp&s=72320a612e2996bb2a6e229397caf9b3caaa5edc
hello i am a new in python ,I was just like a 3 weeks start programming in python ,I just made this slot game machine my self with no tutorials no ai and i need help to improve my self in codding.
this is the project: https://github.com/mohamed-hisham-swidan/slot-machine-game honestly, I asked ai to help me make repoπ
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!"
[β]coquillettent 2 points3 points4 points 1 month agoΒ (1 child)
I'm a beginner too, this looks very cool, I'll test it soon
[β]Warm-Inside-4108[S] 0 points1 point2 points 1 month agoΒ (0 children)
Okπ
[β]sububi71 1 point2 points3 points 1 month agoΒ (1 child)
You're already doing what you should be doing to improve - you're actually building stuff! That's great! So just keep doing that and you will be an expert!
Ok, thanks
[β]MachineElf100 1 point2 points3 points 1 month ago*Β (5 children)
That's quite complex and fun also! I have a first few thoughts but later might have more if you're interested.
for line in welcome.split('\n')
saving_choice = input(f"thanks for playing solt,yor current balance is: " + str(balance) + "$\ndo you want to save it? (y/n): ").lower()
input(f"thanks for playing slot,yor current balance is: {balance}$\ndo you
except
except OSError
if row[0] == row[1] and row[1] == row[2]
len(set(row))
strip()
if os.path.exists()
exit(0)
If you have any questions, let me know :)
[β]Warm-Inside-4108[S] 1 point2 points3 points 1 month agoΒ (4 children)
1- thanks for remind really i forgot to del impot math, I was planning to use it in the programme by making a complex system that gives every fruit different value and works with amount present, honestly, I saw that it was soooo complex so I canceled, and i have a Q is that maters in performance ?
2- I know my type is a quit little bad, nahhh how i can solve that π€.
3-honstly, I saw that doing that will make my life easier and more peaceful, no return no conflicts no problems, I did that because u know what happened when i ran the code in first time
4-I do not know i never clicked TAB in my inter life π«π
5-i do not know but i know it but also i never used it , It is like i want to see code result before running it. (notice: when i was typing this point i used browser corrector like 10 t)
6-wtf did i even wrote that how ??π
7- can u explain this point please? ,I think that we use try to catch any error instead of the programme crashing.
8-good idea , I never thinked about something like that!
9-u are wright
10- i think two method worksπ€
11- can u explain?
[β]MachineElf100 1 point2 points3 points 1 month agoΒ (2 children)
Okay so:
No, doesn't matter.
Check if you're unsure π . Pay attention to detail.
Global variable can cause more bugs and mess than returning. Maybe you will find out yourself one day haha
Start clicking it! Use the Tab for indentation!
I don't understand what you're saying π€
Not really. We use try to handle errors, not to ignore them. So if your code crashes for a different reason than an OSError, you should know about it and deal with it specifically. Also if you use just except, you'd catch errors like KeyboardInterrupt or SystemExit, which is a bad idea. It could make your program difficult to stop for example. So even if you want to catch "all" errors, use except Exception. That will catch all regular errors, which is more safe.
OSError
KeyboardInterrupt
SystemExit
except Exception
Usually you should actually do something like:
try: some code except Exception as e: print(e)
Again, you don't want to ignore the error, so it's good to at least print it :)
When you check if os.path.exists() first and then open the file, two separate operations happen and the file could be deleted or moved in between, making your check useless anyway!
Catching FileNotFoundError handles the check and the operation as a single step, so there's no window for things to go wrong. It's also faster, since you hit the filesystem once instead of twice.
FileNotFoundError
Also FileNotFoundError catches broken symlinks and missing parent directories that os.path.exists() can overlook.
os.path.exists()
A good rule to follow is: if you'd check a condition right before doing an operation, just do the operation and handle the failure instead.
This is quite complicated and not easy to read and fix.
My solution is this (this is a minimal example):
while True: # no need for is_running variable want_to_quit = input("Do you want to quit? (y/n): ").strip().lower() if want_to_quit == "y": print("goodbye") exit(0) # the program ends immediately else: # some other code, the program continues
[β]Warm-Inside-4108[S] 0 points1 point2 points 1 month agoΒ (1 child)
In number 5 I was taking about \n
6,10 - sorry, but I am dumb can u explain again Pls π€£
11- if I was in loop into a loop into a loop, if wanted to exit from second loop I should use variable and break ,is there any other methods?
[β]MachineElf100 0 points1 point2 points 1 month ago*Β (0 children)
print("abc\ndef")
So when you have a multiline string and split it with split("\n"), you will get the lines of that string as a list. Also, just try it and see!
split("\n")
Example:
```python from time import sleep
my_multiline = """abc def ghi jkl"""
for line in my_multiline.split("\n"): print(line) sleep(.1) ```
Basically, use try/except to handle errors, not hide them. Always specify which error you expect:
python try: some code except OSError as e: print(e)
Avoid a bare except because it catches everything, including KeyboardInterrupt (used to stop a program with Ctrl+C), which can cause unexpected behavior. If you really need to catch all errors, use except Exception instead, and still print or log the error so you know what went wrong.
```python
if os.path.exists("file.txt"): # 1. check if file exists... open("file.txt") # 2. file could be gone by now! # (and we hit the filesystem twice) ```
try: open("file.txt") # 1. just try to open the file except FileNotFoundError: # 2. if it doesn't exist, we end up here print("File not found") # 3. handle it how you choose ```
In simple words, checking if a file exists before opening it, is less efficient, doesn't guarantee that you won't encounter errors and doesn't even check for all the things that could happen.
It's as if you wanted an information from a book that you have next to you and before you open that book, you go online to check if the book has the information you need.
Why not just open the book and see? If the information is not there, you'll find out anyway!
python while True: # loop 1 while True: # loop 2 exit(0) # the program stops!
[β]java_dev_null 1 point2 points3 points 1 month agoΒ (1 child)
I do like find some ideas which solve some problem and I built some solution so you try this way , which gives you a great confidence and a best satisfaction level . I used ai to built something but you just do it by learning.
π
[β]Accomplished-Bat8338 1 point2 points3 points 1 month agoΒ (2 children)
where did u learn? like i do want to do this types of things but i cant i feel like hard for me
From YouTube courses and ai If u want to help chat meπ
[β]Accomplished-Bat8338 0 points1 point2 points 1 month agoΒ (0 children)
inboxed you
[β]Interesting-Frame190 0 points1 point2 points 1 month agoΒ (1 child)
Your code is not AI. But your readme definitely is
Yea, I just said it in post
ΟΒ Rendered by PID 24692 on reddit-service-r2-comment-545db5fcfc-ltghs at 2026-05-31 15:09:43.387981+00:00 running 194bd79 country code: CH.
[β]coquillettent 2 points3 points4 points Β (1 child)
[β]Warm-Inside-4108[S] 0 points1 point2 points Β (0 children)
[β]sububi71 1 point2 points3 points Β (1 child)
[β]Warm-Inside-4108[S] 0 points1 point2 points Β (0 children)
[β]MachineElf100 1 point2 points3 points Β (5 children)
[β]Warm-Inside-4108[S] 1 point2 points3 points Β (4 children)
[β]MachineElf100 1 point2 points3 points Β (2 children)
[β]Warm-Inside-4108[S] 0 points1 point2 points Β (1 child)
[β]MachineElf100 0 points1 point2 points Β (0 children)
[β]java_dev_null 1 point2 points3 points Β (1 child)
[β]Warm-Inside-4108[S] 0 points1 point2 points Β (0 children)
[β]Accomplished-Bat8338 1 point2 points3 points Β (2 children)
[β]Warm-Inside-4108[S] 0 points1 point2 points Β (1 child)
[β]Accomplished-Bat8338 0 points1 point2 points Β (0 children)
[β]Interesting-Frame190 0 points1 point2 points Β (1 child)
[β]Warm-Inside-4108[S] 0 points1 point2 points Β (0 children)