I know, silly question, but I am not a programmer and really need to known...
to look-for-food
if food > 0
[ set color orange + 1
set food food - 1
rt 180
stop ]
if (chemical >= 0.05) and (chemical < 2)
[ uphill-chemical ]
end
Thanks
This language is called LOGO. It's often used with Turtle -- drawing lines on the screen.
Related Anecdote:
My first encounter with a computer was around 1985, in my classroom we had an Apple (Apple ][ probably?). This was one of the main programs that was available. I had learned how to do to in order to define a subroutine. I tried it once, but I couldn't remember the syntax for defining the specifics. And then when I tried to exit the to routine definition context, I couldn't remember how to exit it. The teacher could sense that I was confused, and was coming over to help me. I figured I'd be in trouble for straying beyond the scope of the exercise that I was supposed to be working on, and figured the teacher wouldn't know how to recover either. I panicked and powered off the computer. My first "did you try turning it off and on again?" experience! :)
Related
I'm trying to print some RFID tags and retrieve their TIDs to store them in my system and know which tags have been printed. Right now I'm reading the TID and sending it back to my computer (connected via USB with the my ZT421 printer) with the following code:
^RFR,H,0,12,2^FN0^FS^FH_^HV0,24,,_0D_0A,L^FS
^RFW,H,2,12,1^FD17171999ABABABAAAAAAAAAB^FS
This is repeated for each tag that I'm printing. However, when printing 10 tags, I only get 9 TIDs. If after that I try to print 7 tags, I still get 9 TIDs. To be honest I'm a bit lost now, because even trying to use the code examples from the ZPL manual (I've tried the ^RI instruction also) it doesn't seem to work.
The communication with the printer is beeing done through Zebra Setup Utilities' direct communication tool.
I tried to retrieve each printed tag TID with:
^RFR,H,0,12,2^FN0^FS^FH_^HV0,24,,_0D_0A,L^FS
^RFW,H,2,12,1^FD17171999ABABABAAAAAAAAAB^FS
but I always get 9 TIDs.
I also tried getting the TID with the ZPL manual example for the ^RI command:
^XA
^FO20,120^A0N,60^FN0^FS
^RI0,,5^FS
^HV0,,Tag ID:^FS
^XZ
And I got absolutely nothing returned to the computer, just a mssage saying "Tag ID:" and no value shown.
I would really appreciate some help with this...
Thanks in advance!
I've fixed the issue, but I'm going to leave the solution here just in case someone else is facing the same problem.
I thought that maybe it wasn't a code issue, but something related to the computer-printer communication. It turned out to be the case. The Zebra Setup Utilities program has a button that says "options". If you click it, a new screen will open and there you can configure the seconds that the program will wait for the printer response (in this case through USB). By default it's set to 5, i changed this value to 100, which is the maximum. This meant that instead of just printing and retrieving the TIDs of 6-9 tags, now I can do it for about 100.
This is not amazing because in my case it implied creating 25 files for the 2500 tags I had to print and store the TIDs, however it's far better than before.
I have been working on a discord.py bot when yesterday, on my bus, some of my code got deleted. Everything was working fine, but now my joke command doesn't work. I am pretty new to coding as this is my 2nd week, but can someone explain to me why this says invalid syntax?
#bot.command()
async def joke(ctx):
responses = [
"Two hunters are out in the woods when one of them collapses. He's not breathing so his friend calls 911. My friend is dead! What should I do? The operator replies, Calm down sir, first make sure that he's really dead. There's a silence, then a loud bang. Back on the phone, the guy says, Ok, now what?",
"I threw a boomerang a few years ago; now I live in constant fear.",
"Someone stole my mood ring. I don't know how I feel about that.",
"Women call me ugly until they find out how much money I make. Then they call me ugly and poor.",
"You're not completely useless: you can serve as a bad example.",
"I broke my finger last week. On the other hand, I'm okay.",
"Appearantly someone in London gets stabbed every 52 seconds. Poor bastard.",
"A Roman legionaire walks into a bar, holds up two fingers, and says, Five Beers please!"
await ctx.send(f'{random.choice(responses)}')
Your missing a closing bracket at the end of your list.
I am 11 years old and am keen programmer learning Python.
1) I am programming a guess the number game and when I ask the user if they want to play again, I get a semantic error (I think this is the correct way to describe it) where if I input "no", "n", "NO" or "N", the if statement is still executed, causing the loop() function to run again, after calculating scores. Take a look at the following image (sorry about the cluttered windows).
Play again error: https://i.stack.imgur.com/TsEyw.png
Here is a link to the rest of the program:
https://gist.github.com/anonymous/f9be138e07c569b8721b990293d92314 (I only have 8 reputation points) , but I am looking at just this snippet:
def play_again():
again = input("\nWould you like to play again? y/n " + prompt)
if again.upper() == "Y" or "YES":
global gu_num
percent = gu_num * 10
score = 100 - percent
highscores = [{round: (score)}]
current_score = {round: (score)}
highscores.append(current_score)
print("Lets see if you can beat your score of " + str(current_score[round]) + ".\nHere we go!")
gu_num = 0
loop()
elif again.upper() == "N" or "NO":
print("Ok then.\nThank you for playing Guess The Number and I hope to see you again soon!\nThis game was created and devoloped by Kiran Patel (me), age 12. If you liked this game or want to talk to me about -->anything<--, please do email me at kiran#inteleyes.com. It'll make me happy! Thank you for playing Guess the number with me.\n\n program was developed by Kiran Patel in 2017 ad.")
input("\n\nPress the enter key to exit")
quit()
else:
print("Sorry, I don't understand. Please try again:")
play_again()
2) I'm having a similar problem with the part of my code which starts to handle files. When I input a 'no' (same if expression) the program will execute the part of that if statement which creates the file (take a look at this image: file saving result and this image: file operations code). Note that the 'file operations code' image prints out the file-save error message because I hadn't given perms to write in prog'/files folder. I know it has tried to save the file because of the error message that was printed out (I intended the error message to be printed out).
3) Also, does anyone know what #!/usr/bin/python means? I know its hashtagged out, but I have seen it before like this and I was wondering what it means.
As always, ANY help will
be appreaciated, so please don't hesitate on adding something that is not directly relevant to the question, because I may well have missed it (unless it is completely irrelevant).
Once again, thanks in advance for your help.
From Kiran
The problem is here (and on every line that looks like it):
if again.upper() == "Y" or "YES":
Here's what you (reasonably) assume it's doing (This is how you would fix it, btw):
if (again.upper() == "Y") or (again.upper() == "YES"):
Here's what it's actually doing:
if (again.upper() == "Y") or "YES":
So let's say that you typed Q at the prompt. As Python reads along the line, it sees the first comparison operator, ==, and compares just the two things on either side of it: "Q" and "Y". "Those are not equal", thinks Python, and moves on to the next part: comparing False - the answer to the first part - with "YES".
In Python, if something exists and isn't False or 0 or something similar, it gets treated as True. "False is False, but "YES" is a perfectly valid string", thinks Python. "and the or operator means that if either of these two things is True, the whole thing is True, so this must all be true and I should run this block of code now." And so it does, every time, no matter what you type.
As a general rule, when you're doing these kinds of tests, it's only safe to do one comparison at a time. Any more than that and it's time to bring in the parentheses.
Also, regarding #!/usr/bin/python: the #! is called a Shebang, and it's not part of Python at all - it's part of your operating system (assuming your operating system isn't Windows). It says to your OS: "This may look like an ordinary text file, but it's actually a script, which you should run using the program located at /usr/bin/python".
I am trying to export a turtle variable value that is <= item 0 of a patch list. These are the values I am interested in recording, but I am having trouble getting the code right for that.
I've tried below:
file-print turtles with [turtlevariable <= item 0 patchlist]
I know that's not right as I am getting the number of turtles, and not the turtle variable value. I would like to run this model 1000 times and am unsure how to create code for a file that will be manageable to manipulate in Excel.
I'm pretty sure there is a simple answer, but I just can't figure it out! Any help is greatly appreciated.
You have multiple questions here. You need to post each question separately. I will take on the following: how can you get a list of values for turtlevariable, but only for the values that are < item 0 patchlist.
globals [patchlist]
turtles-own [tvar]
patches-own [pvar]
to test
ca
ask patches [set pvar random-float 1.0]
set patchlist [pvar] of patches
let _p00 item 0 patchlist ;;compute only once
crt 100
ask turtles [set tvar random-float 1.0]
let _tset (turtles with [tvar < _p00])
let _tvals [tvar] of _tset
print _tvals
end
You can always file-print anything you can print, so now you need to decide how exactly you want to format this list. This is a separate question. If you want to save as .csv, that is a separate question. (But you will find multiple questions on this site addressing that.) If you want to create one output file for multiple replicates, that is a separate question. (But see questions on this site about BehaviorSpace.) Hth.
When I play the sound file by itself (in interface) it works fine and plays all the way through. However, when I play it as part of the code (followed by an action) it only plays the first half second. I'm using sound:play-sound-and-wait, so I'm not sure why it isn't working.
extensions [sound] ; I have them in the same folder
to-report mouse-up?
ifelse mouse-down?
[report "false"]
[report "true"]
end
to twirl
if mouse-up?
[ask turtles with [shape = ballerina]
[set shape ballerina-2
twirl]
ask turtles with [shape = ballerina-2]
[set shape ballerina
twirl] ]
end
These are 2 different ballerina's facing different directions. When you switch between them, they look like they're twirling. She keeps doing that until you make her stop
to ballet-box
ask patches [set plabel-color 105] ;gives the background this color
sound:play-sound-and-wait "love.aif" ;this works perfectly fine in interface
twirl ;and then I want the ballerina to twirl until you make her stop
end
Any help would be super appreciated!
Sounds like http://github.com/NetLogo/Sound-Extension/issues/2 or http://github.com/NetLogo/Sound-Extension/issues/3 . I don't think anyone has yet investigated or attempted to fix these issues. I don't think we even know under exactly what circumstances they do or don't occur.