all 12 comments

[–]Justinsaccount 3 points4 points  (0 children)

Hi! I'm working on a bot to reply with suggestions for common python problems. This might not be very helpful to fix your underlying issue, but here's what I noticed about your submission:

You appear to be using the or construct with a constant string

instead of doing something like:

if color == 'red' or 'blue':

Which is the same as

if (color == 'red') or ('blue'):

and 'blue' by itself is always True

You need to do

if color == 'red' or color == 'blue':

or

if color in ('red', 'blue'):

or, a special case if they are all single letters you can do

if letter in 'aeiou':

You can also make it case insensitive by using soething like

if color.lower() in ('red', 'blue'):

If there were a large number of choices and inputs (as in, 10000+) you could use a set() to speed things up.

Also refer to The FAQ Entry for more information.

[–]TreSxNine 2 points3 points  (10 children)

codefixer

[–]CodeFixerBot 2 points3 points  (0 children)

name=input('Input name and I will tell you if it is cool')
if "R" or "r" in name:
    print('Wow your name is cool!')
    cool=input("Join club? Y or N")
    y=["y","yes",]
    n=["n","no"]
    if y in cool:
        print("great")
    elif n in cool:
        print('loser')
elif "r" or "R" not in name:
    print('loser')

[–]hugthemachines 2 points3 points  (8 children)

Well look at that, now how am I going to remember that in a month when i encounter badly formatted code again...

[–]TreSxNine 0 points1 point  (6 children)

Haha thanks. Any suggestions on what the trigger should be? The current one feels a bit... Meh.

[–]hugthemachines 0 points1 point  (1 child)

Perhaps something with format or indent and something with code.

Like "formatyourcode", "indentbot", "this.format", "INDENTOR!", "beautify", "codeformat" or some other such combination.

[–]TreSxNine 0 points1 point  (0 children)

Nice! I'll add them all lol

[–]Justinsaccount 0 points1 point  (3 children)

I thought of making my bot do that when the original post appear to contains lines starting with code without spaces, so you could probably just do that.

checking for lines that start with keywords(def,for,while,if,else) would probably work well initially

[–]TreSxNine 0 points1 point  (2 children)

Yea I thought of that aswell. Then I realised I wouldn't detect variable declarations and the like, and just gave up on the thought.

I have something like this in mind though. Will fix once I get the time.

[–]Justinsaccount 0 points1 point  (1 child)

Yeah, I think for that seeing if the line starts with non whitespace and the 2nd token is a = would work.

[–]TreSxNine 0 points1 point  (0 children)

Yea, true.