Ask Your Question
4

In Python, I am getting arbitrary numbers during a game where I add and subtract values.

asked 2021-10-11 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-05-20 15:00:00 +0000

djk gravatar image

There are several possible causes for arbitrary numbers in a Python game where values are added and subtracted. Here are a few things to check:

  1. Make sure that you are using consistent data types when doing calculations. For example, if you are adding an integer and a float, Python will convert both values to floats, which could lead to unexpected results.

  2. Check that you are initializing variables correctly. If you don't initialize a variable before using it, it will have an arbitrary value that could affect your calculations.

  3. Make sure that you are not modifying variables outside of the scope where they are defined. This can happen if you accidentally reuse variable names or forget to pass variables as arguments to functions.

  4. Check that you are not accidentally modifying immutable objects. For example, if you try to modify a string or a tuple, Python will create a new object rather than modifying the existing one.

  5. Consider adding print statements to your code to help you debug. Print out the values of variables at different points in the code to see if there are any unexpected changes or inconsistencies.

By following these steps and carefully examining your code, you should be able to track down the source of the arbitrary numbers in your game.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-10-11 11:00:00 +0000

Seen: 8 times

Last updated: May 20 '21