Bitcoin Forum
May 21, 2024, 11:44:55 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Learning Python part 3  (Read 1171 times)
vite (OP)
Legendary
*
Offline Offline

Activity: 1018
Merit: 1000


View Profile
September 07, 2013, 06:16:35 AM
 #1

Well i'm half way through LPTHW at this point the book wants me to memorize symbols and their functions and practice.

So to take a break from the usual study drill I decided to make an automata to run on top of something called.

LABY a game it seems to solve the maze part of the problems roughly about 4 of them.

You can review my attempt at the game here:

https://gist.github.com/vitepython/6472113

Note: Op is not a programmer and is learning this as a hobby.
b!z
Legendary
*
Offline Offline

Activity: 1582
Merit: 1010



View Profile
September 07, 2013, 06:42:39 AM
 #2

So are you learning to code, or playing a game? or both?
vite (OP)
Legendary
*
Offline Offline

Activity: 1018
Merit: 1000


View Profile
September 07, 2013, 01:47:36 PM
 #3

So are you learning to code, or playing a game? or both?

Learning to code
Solving the LABY maze challenges was to test what I have learned so far.
jackjack
Legendary
*
Offline Offline

Activity: 1176
Merit: 1255


May Bitcoin be touched by his Noodly Appendage


View Profile
September 07, 2013, 03:04:19 PM
 #4

Where is robot.py?

Quote
while x == 3 - 4:
Do you really mean while x==-1?

Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2
Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
vite (OP)
Legendary
*
Offline Offline

Activity: 1018
Merit: 1000


View Profile
September 07, 2013, 03:14:09 PM
 #5

Where is robot.py?

Quote
while x == 3 - 4:
Do you really mean while x==-1?

Robot.py comes within LABY if you see the gist comment; the link to laby is there.

Hmm since x is a random generated number I thought I was telling pythin if x equals 3 or 4 then go back to function...

Edit : if u run ubuntu desktop you can install it from the software center.
FirstAscent
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1000


View Profile
September 07, 2013, 03:24:16 PM
 #6

Where is robot.py?

Quote
while x == 3 - 4:
Do you really mean while x==-1?

Robot.py comes within LABY if you see the gist comment; the link to laby is there.

Hmm since x is a random generated number I thought I was telling pythin if x equals 3 or 4 then go back to function...

Then it should be:

while x == 3 or x == 4:

In your code, it should be obvious that 3 - 4 is an expression which subtracts 4 from 3. Furthermore, - has greater precedence than ==, thus the expression 3 - 4 evaluates before the equality operator. Finally, 3 and 4 are constants, thus the interpreter can evaluate them at compile time, if it does do a mini-compile upon running, and convert them into the value -1.

Now, let's look at some aspects of precedence and predicates.

If the == operator had greater precedence than the - operator (which it doesn't), then we would have a statement which attempts to subtract 4 from the value of True or False. If coding in C, which you are not, the equality expression would evaluate to 0 or 1. Interestingly, we could do this:

while((x == 3) - 4) {

Which would evaluate to -3 if x did indeed equal 3.
vite (OP)
Legendary
*
Offline Offline

Activity: 1018
Merit: 1000


View Profile
September 07, 2013, 03:44:55 PM
Last edit: September 07, 2013, 04:32:01 PM by vite
 #7

What I find odd is that the ant is behaving the way I want it to behave. Meaning that if random outputs 3 or 4 it moves forward.

I guess I should do x == none instead. To break the loop  Huh

Just trying to figure out why the ant behaves as intended.

Edit: figured it out
X >= 3

That way %50 it will check to move forward
And the rest of the other time it will try left or right
The behavior can be altered by increasing/decreasing the range of the random numbers
vite (OP)
Legendary
*
Offline Offline

Activity: 1018
Merit: 1000


View Profile
September 07, 2013, 04:46:18 PM
 #8

Disregard the previous solution and thanks for the feedback...

I will just remove x == 3 - 4 all together,
since I have the range from 1 to 4
if it does not generate 1 or 2 in the random number it will go back to function to check on other conditions and just move accordingly.
polrpaul
Full Member
***
Offline Offline

Activity: 238
Merit: 100


Love the Bitcoin.


View Profile WWW
September 07, 2013, 04:50:43 PM
 #9

this probably belongs in a python developers forum?  Undecided

BTC.sx - Leveraged Bitcoin Trading. Simply use Bitcoin to take advantage of a rising or falling Bitcoin price.
jackjack
Legendary
*
Offline Offline

Activity: 1176
Merit: 1255


May Bitcoin be touched by his Noodly Appendage


View Profile
September 07, 2013, 06:17:03 PM
 #10

You can use "while x in [3, 4]"

Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2
Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
Moogle
Full Member
***
Offline Offline

Activity: 238
Merit: 100


KUPO!


View Profile WWW
September 07, 2013, 11:04:04 PM
 #11

Good effort :-) I'm trying to learn java in my spare time. Wanna start making some apps for my phone :-P might finally be able yo get all my ahitty c# games playable on a phone :-D

FirstAscent
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1000


View Profile
September 08, 2013, 01:38:31 AM
 #12

Are we dealing with floats?

In such a case, perhaps you meant something like this:

while x >= 3 and x < 4:
vite (OP)
Legendary
*
Offline Offline

Activity: 1018
Merit: 1000


View Profile
September 09, 2013, 08:15:05 PM
 #13

Are we dealing with floats?

In such a case, perhaps you meant something like this:

while x >= 3 and x < 4:

Are we dealing with floats?

In such a case, perhaps you meant something like this:

while x >= 3 and x < 4:

both  this solutions  give me an error within laby

using if and or gives me and error

The best thing was to do

if x == 1:
    left()
if x == 2:
    right()
main()
FirstAscent
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1000


View Profile
September 09, 2013, 08:25:00 PM
 #14

What error?
vite (OP)
Legendary
*
Offline Offline

Activity: 1018
Merit: 1000


View Profile
September 11, 2013, 12:31:17 PM
 #15

What error?

The solutions you offered are written correctly.

But it seems the game LABY does not have a complete python library or just cannot read them.

Gives me a track... syntax... on line depending on where I placed the code.
FirstAscent
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1000


View Profile
September 11, 2013, 04:48:06 PM
 #16

Well, I don't know anything about LABY. Why don't you write some code from the ground up?

Here's a good project for you: Write a program that builds a 2d road network using recursion, by growing roads one branch at a time, creating a road topology that is reasonable and authentic looking, including urban areas, suburbs, and rural areas. Print the topological data out to a Renderman RIB file, and use the freely available 3Delight renderer to render the network.

Use this paper as inspiration, but do not adopt the L-system methodology: http://graphics.ethz.ch/Downloads/Publications/Papers/2001/p_Par01.pdf
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!