But serial monitor does not give an intended output. Even before the void loop runs, it seems as though garbage output comes out. I checked other posts and saw that baud rate must be same as the number in Serial.begin(). However, I have checked that both of them have the same number as 9600. I also found others do not have the same issue as mine. If there is any solution available to this, I will greatly appreciate the help!
It did not work . It's a dumb question, but if Arduino is partially fried, is this possible?
Your Arduino is probably fine. Everything else is fine too. There is nothing intrinsically wrong with your code either. I submit that the only problem is that it is an essentially stupid and pointless exercise. If you added a zero to the delay it will probably be OK. This is the sort of problem that goes away once you start doing something useful. If the extra delay doesn't fix it, it is time for everyone to get worried.
The only way you will ever see output before the loop is when you put an output command in the setup - which you haven't.
There is nothing to suggest that the above has anything to do with the original question. There is nothing to suggest that the serial monitor is broken either. One might say that you are trying to abuse it, but it will survive.
Maybe you are running two threads at once....
I think you should have some kind of session protocol anyway, when two machines are communicating. The Python side should be looking for some kind of valid message from the Arduino before initiating a session. Probably the reverse too. Then the startup garbage won't matter.
I am sorry if this post was bad since I am a beginner in python and arduino. What I decided to do was to have python codes that order not to read the values if invalid. I realized that it's important to try fixing problems myself before attributing the issues to the hardware.
Thank you so much for all the help that has helped me solve this problem and grow more.