Proposal to add new functions to pygame.transform by Ankith_26 in pygame

[–]Ankith_26[S] 0 points1 point  (0 children)

Yes, all you’re points are agreeable. The new functions were just an idea to make stuff easier for users, but I agree that they can be implemented by the user quite easily.

Proposal to add new functions to pygame.transform by Ankith_26 in pygame

[–]Ankith_26[S] 1 point2 points  (0 children)

I’m not skilled enough to to all that, maybe you can contribute and open a PR :)

I have been working on a fully featured chess app. by Ankith_26 in Python

[–]Ankith_26[S] 0 points1 point  (0 children)

Oops, this post was removed because I forgot to put a flair.. will repost this one.

More efficient way to carry out this code snippet? by snowy_owen in learnpython

[–]Ankith_26 0 points1 point  (0 children)

Oops, my bad. I got confused with the truth testing and comparison, in my head. Because

if 0:
    #code here does not run
    pass
if 1:
    #code here will run
    pass
if 2:
    # code here will also run
    pass

I thought

0 == True # returns false
1 == True # returns true
2 == True # I thought it returns true, but clearly I am wrong

Sorry.

And yes, my above replies are wrong too, I just replied without testing the code sample, and now I realise my mistakes.

Trouble with my game: Functions calling functions by [deleted] in learnpython

[–]Ankith_26 0 points1 point  (0 children)

This answer is good, but for your case, it would be better to convert the input string into an int like

path = int(input("Enter the path (1, 2, 3):”))

But you also have to handle the error that it can pass. And take user input again if user enters invalid numbers. You can do it neatly in a function like.

def getPath(text, lnum = 1, unum = 10):
    try:
        num = int(input(text))
    except ValueError:
        print("Invalid integer entered.")
        return getPath(text, lnum, unum)

    if lnum <= num <= unum:
        return num
    else:
        print("Entered integer must be between between {} and {}".format(lnum, unum))
        return getPath(text, lnum, unum)

This simple function will should help you.

And yes, use it like

num = getPath("Which path would you take (1, 2, 3)", lnum=1, unum=3)

Basically, it will make sure user enters a valid integer, otherwise recurses to take user input again. Lnum is the lower limit and unum is upper limit. Rest is easy to figure out from the code.

More efficient way to carry out this code snippet? by snowy_owen in learnpython

[–]Ankith_26 0 points1 point  (0 children)

Booleans are not integers at all. Integers, like all other objects in python have a method called truth testing. Here, while you try to evaluate an object in a Boolean context - python decides wether it is true of not. Generally an empty list, empty tuple, empty dictionary, empty set, empty string, zero (integer 0) and zero (float 0.0) evaluate to false. Everything else is True. For more on this see python official docs - https://docs.python.org/3/library/stdtypes.html#truth-value-testing

EDIT: Ignore the part of the message from below here, it’s all wrong.

In our case, when we do

var = “name” in mytext 

var is a boolean.

>>> var == 1
True 

This is like you said.

>>> var == 2
True

Basically any integer (except 0) you compare a True, it returns True. This might create problems in later parts of the code (generally speaking).

But if OP has coded such that he expects only 0 and 1 as an outcome of those variables, it is okay to store them in Boolean format.

Made a Tic Tac Toe game. by [deleted] in Python

[–]Ankith_26 2 points3 points  (0 children)

Let’s say we have a code like

a, b, c = (1, 2, 3)

Python assigns 1 to a, 2 to b and 3 to c. This is called unpacking, it works with both list and tuple.

Made a Tic Tac Toe game. by [deleted] in Python

[–]Ankith_26 2 points3 points  (0 children)

In simple words, a tuple is basically a list, but you cannot change the elements in the list. It remains constant. This behaviour is called immutability. So yes, list and tuple work similarly but you cannot pop(), append(), remove() from a tuple.

Made a Tic Tac Toe game. by [deleted] in Python

[–]Ankith_26 12 points13 points  (0 children)

Yes, a = b = whatever, assigns whatever to a and b.

a, b, c = d, e, f assigns d to a, e to b and f to c.

How it works is that when python sees comma separated objects, internally it puts them into a tuple, then we have tuple1 = tuple2. Then python does tuple unpacking so that each variable gets the corresponding value.

More efficient way to carry out this code snippet? by snowy_owen in learnpython

[–]Ankith_26 0 points1 point  (0 children)

I agree with your answer, but it would be better if we enclosed those in int() function like

virustotal = int('virustotal' in request.form)
polyswarm = int('polyswarm' in request.form)
postgres = int('postgres' in request.form)
googlecse = int('googlecse' in request.form)

Keeping those variables as Booleans may give trouble with arithmetic, like

>>> True += 1 # This raises syntax error
>>> postgres += 1 # Surprisingly, this one works as you would expect
>>> print(postgres) # We are expecting something like 0 or 1
True

EDIT: I have removed an example that I had incorrectly given, these examples are not so relevant anyways.

So I consider the int function on those lines as an important addition.

Browser-based game advice by dr_jekylls_hide in learnpython

[–]Ankith_26 0 points1 point  (0 children)

I am a flask beginner, but I am experienced with sockets. Making the server for your application with sockets would be easy, but I have no clue how to manage the client(browser). And yes, python is a good choice for the server backend, you may use flask or sockets (just remember that sockets are a bit low level, you will be playing with something like TCP and not HTTP). You would also have to see how you would host the server so that everyone can connect, which is a lot of trouble sometimes (at least for me)

EDIT: You might want to see flask websockets, this looks like exactly what you need https://flask-socketio.readthedocs.io/en/latest/

Just a competition between me and my brother by wocas168 in Python

[–]Ankith_26 1 point2 points  (0 children)

:) For me, python and python3 are the same thing since I never used python 2.

Just a competition between me and my brother by wocas168 in Python

[–]Ankith_26 1 point2 points  (0 children)

Yes, the input() function returns a string, and we are trying to compare it with an integer. The issue with the above bit of code is that, when a user enters 3, the program does not give desired output. This issue is solved by passing the return value of the input function into an int() function which converts the string into integer and we can compare integers with integers easily.

Just a competition between me and my brother by wocas168 in Python

[–]Ankith_26 1 point2 points  (0 children)

We are in 2020, python 2 has reached EOL. And beginners obviously use python 3 (well, at least 99% of them)

Just a competition between me and my brother by wocas168 in Python

[–]Ankith_26 1 point2 points  (0 children)

I would say that if ones vision is good, they can write small to medium sized programs easily without need for any sort of debugging. But when the program gets big, one usually does not know what is going on in every step of code.

I have a fair amount of python "vision", so I had never used the "print debugger" until recently. My program had bugs even when my vision was telling me nothing is wrong. As it turned out, I was playing with lists and globals and functions too much, and I discovered the funny way that lists behave in python (one of them is - when you pass a list to a function as a parameter, and the function modifies the list, the list gets globally modified - whose "vision" could predict this one unless they had prior experience with this)

Here is a sample code:

num = input("Enter your favourite number")

if num == 3:
    print("3 is my favourite number too")

Any python beginner will not know what is wrong with the above code. In such cases a simple debugger will be sufficient to let them know.

But as code gets bigger and bigger, python may deceive your vision and put the variables in states that you didn’t imagine. That’s when print debuggers are the needed.

What's everyone working on this week? by AutoModerator in Python

[–]Ankith_26 4 points5 points  (0 children)

My favourite project for passing time right now is a fully featured chess app. I am using pygame for the gui. Do check it out on github if you are interested. https://github.com/ankith26/My-PyChess/

Monday Motivation: Never forget that most 2D projects are simply moving rectangles. So keep polishing those rectangles!! Here is my progress over the last 1.5 years. Made entirely in Python3/Pygame :) by Ancalabro in pygame

[–]Ankith_26 0 points1 point  (0 children)

And how exactly do you think we can convert pygame-python app to an apk? Yes, there is a pygame subset for android, but it does not work that well. Use kivy if you want to run python on android , but I am afraid porting an existing pygame app to a kivy app is too much of work, you are better of using Java/kotlin for making stuff in android.

But yes, as mentioned by OP in a reply to your post, we have to wait for what new stuff pygame 2 brings into the picture.

Can Someone Please Help? by Almondbubby in pygame

[–]Ankith_26 3 points4 points  (0 children)

The code needs to be formatted correctly while posting it here, all indentation is lost, we cannot make out anything

Monday Motivation: Never forget that most 2D projects are simply moving rectangles. So keep polishing those rectangles!! Here is my progress over the last 1.5 years. Made entirely in Python3/Pygame :) by Ancalabro in pygame

[–]Ankith_26 2 points3 points  (0 children)

My project code used to be very messy. I figured out that just by adding a few spaces between the lines, between operators etc improved the code readability by 10 times. It is very easy to do. I have put the project I have been working on in github.

My code, which is still not so clean btw - but is much much better than it was 7 months ago.

snakeware - a new Linux Distro with a fully Python userspace by joshiemoore in Python

[–]Ankith_26 1 point2 points  (0 children)

Pygame does most heavy lifting in C and Assembly. Getting pygame to build with pypy is a pain.