Discuss Scratch

mybearworld
Scratcher
1000+ posts

Python programming language

Yes, but only in conditions like these:
if 1==1:
    print("The world is sane.")
elif 2==2:
    print("Okay, 2 is 2.")
else:
    print("WHAT IS GOING ON")
But you don't use it like this:
if 1==1:
    print("The world is sane.")
elif 2==2:
    print("Okay, 2 is 2.")
else 3==3:
    print("Uh...")
Elif stands for “else if”.
dertermenter
Scratcher
1000+ posts

Python programming language


With help from @MyBearWorld , this is my first python game.

If you want to play here is the code!!!!

import random
computer = random.randint(1,10)
number = int(input(“Pick a number between 1 and 10!”))
if computer > number:
print(“Sorry, you lose. The computers number was bigger than yours! The computers number was”,computer,“and your number was”,number,“. \n That is a difference by”,computer - number,“. Better luck next time!”)
elif number > computer:
print(“Woop woop! You win! Your number was bigger than the computers! Your number was”,number,“And the computers was”,computer,“. /n That is a difference by”, number - computer,“!”)
elif number == computer:
print(“Draw. You and the computers number was the same! You both picked”,computer,“!”)

I hope it is OK lol. Enjoy!


still prefer javascript a lot more
mybearworld
Scratcher
1000+ posts

Python programming language

dertermenter wrote:


With help from @MyBearWorld , this is my first python game.

If you want to play here is the code!!!!

import random
computer = random.randint(1,10)
number = int(input("Pick a number between 1 and 10!"))
if computer > number:
print("Sorry, you lose. The computers number was bigger than yours! The computers number was",computer,"and your number was",number,". \n That is a difference by",computer - number,". Better luck next time!")
elif number > computer:
print("Woop woop! You win! Your number was bigger than the computers! Your number was",number,"And the computers was",computer,". /n That is a difference by", number - computer,"!")
elif number == computer:
print("Draw. You and the computers number was the same! You both picked",computer,"!")

I hope it is OK lol. Enjoy!


still prefer javascript a lot more
Code tags are better, because copy and paste doesn't work.

Cool, but it's “\n”
Also:
Pick a number between 1 and 10!11
Woop woop! You win! Your number was bigger than the computers! Your number was 11 And the computers was 2 . /n That is a difference by 9 !

Last edited by mybearworld (April 9, 2021 10:17:30)

Vaibhs11
Scratcher
1000+ posts

Python programming language

dertermenter wrote:

import random
computer = random.randint(1,10)
number = int(input("Pick a number between 1 and 10!"))
if computer > number:
    print("Sorry, you lose. The computers number was bigger than yours! The computers number was",computer,"and your number was",number,". \n That is a difference by",computer - number,". Better luck next time!")
elif number > computer:
    print("Woop woop! You win! Your number was bigger than the computers! Your number was",number,"And the computers was",computer,". /n That is ", "a difference by ", number - computer,"!")
elif number == computer:
    print("Draw. You and the computers number was the same! You both picked",computer,"!")
You should've used code=py more than quote.
I'll make the game better.
import random
computer = random.randint(1,10)
number = int(input("Pick a number between 1 and 10!"))
while 1==1:
  if computer > number:
    print("higher \n")
  elif number == computer:
    print("Draw \n")
    break
  elif number > computer:
    break
print("Woop woop! You win! Your number was bigger than the computers! Your number was ",number," and the computers was ",computer,". /n That is 
a difference by ", number - computer,"!")

dertermenter wrote:

still prefer javascript a lot more
That's the spirit!

Last edited by Vaibhs11 (April 9, 2021 10:36:29)

mybearworld
Scratcher
1000+ posts

Python programming language

Vaibhs11 wrote:

import random
computer = random.randint(1,10)
number = int(input("Pick a number between 1 and 10!"))
while 1==1:
  if computer > number:
    print("higher")
  elif number == computer:
    print("Draw. You and the computers number was the same! You both picked",computer,"!")
  elif number > computer:
    break
print("Woop woop! You win! Your number was bigger than the computers! Your number was",number,"And the computers was",computer,". /n That is 
a difference by", number - computer,"!")
NO.
NOO.
NOOOOOO.
Vaibhs11
Scratcher
1000+ posts

Python programming language

mybearworld wrote:

Vaibhs11 wrote:

import random
computer = random.randint(1,10)
number = int(input("Pick a number between 1 and 10!"))
while 1==1:
  if computer > number:
    print("higher")
  elif number == computer:
    print("Draw. You and the computers number was the same! You both picked",computer,"!")
  elif number > computer:
    break
print("Woop woop! You win! Your number was bigger than the computers! Your number was",number,"And the computers was",computer,". /n That is 
a difference by", number - computer,"!")
NO.
NOO.
NOOOOOO.
too late I corrected my code.
roketH77
Scratcher
1000+ posts

Python programming language

Hey, I’m getting into python, but I don’t know much lol. Can you give me some beginner tutorials you recommend/used? Thanks!
Edit: I plan on using visual studio on windows, if this bears any weight.

Last edited by roketH77 (April 17, 2021 12:39:33)

gosoccerboy5
Scratcher
1000+ posts

Python programming language

roketH77 wrote:

Hey, I’m getting into python, but I don’t know much lol. Can you give me some beginner tutorials you recommend/used? Thanks!
Edit: I plan on using visual studio on windows, if this bears any weight.
Honestly, Python is a pretty intuitive language if you know Scratch already, I would recommend w3schools.com but I'm probably gonna get yelled at for that (tbh you should use w3schools for simpler stuff only)
-EmeraldThunder-
Scratcher
1000+ posts

Python programming language

Does anyone know how to change things like your about me and what I'm working on in python?
gosoccerboy5
Scratcher
1000+ posts

Python programming language

-EmeraldThunder- wrote:

Does anyone know how to change things like your about me and what I'm working on in python?
The best url I could get with the network log while saving my About Me was https://scratch.mit.edu/site-api/users/all/${username}/, which does something weird when I try to visit the url.

Last edited by gosoccerboy5 (April 17, 2021 13:47:25)

PowerOfStars
Scratcher
100+ posts

Python programming language

I am advanced in python

Last edited by PowerOfStars (April 17, 2021 13:49:15)

roketH77
Scratcher
1000+ posts

Python programming language

gosoccerboy5 wrote:

roketH77 wrote:

Hey, I’m getting into python, but I don’t know much lol. Can you give me some beginner tutorials you recommend/used? Thanks!
Edit: I plan on using visual studio on windows, if this bears any weight.
Honestly, Python is a pretty intuitive language if you know Scratch already, I would recommend w3schools.com but I'm probably gonna get yelled at for that (tbh you should use w3schools for simpler stuff only)
I’ll just look on YouTube lol
Edit: I was gonna look on there anyway

Last edited by roketH77 (April 17, 2021 16:34:41)

mrcoat
Scratcher
100+ posts

Python programming language

Hello I'm using python to make something that accesses my scratch messages, but it keeps giving me an access denied thing, how would I be able to get access to it using python? Thank yu!

also

PowerOfStars wrote:

I am advanced in python
guy if your advanced can i get help with this?
roketH77
Scratcher
1000+ posts

Python programming language

mrcoat wrote:

Hello I'm using python to make something that accesses my scratch messages, but it keeps giving me an access denied thing, how would I be able to get access to it using python? Thank yu!

also

PowerOfStars wrote:

I am advanced in python
guy if your advanced can i get help with this?
You have to have some sort of key that you get through JavaScript, but that’s all I know.
mybearworld
Scratcher
1000+ posts

Python programming language

mrcoat wrote:

Hello I'm using python to make something that accesses my scratch messages, but it keeps giving me an access denied thing, how would I be able to get access to it using python? Thank yu!

also

PowerOfStars wrote:

I am advanced in python
guy if your advanced can i get help with this?
You need to give your token, what I have no idea how t get
mrcoat
Scratcher
100+ posts

Python programming language

mybearworld wrote:

mrcoat wrote:

Hello I'm using python to make something that accesses my scratch messages, but it keeps giving me an access denied thing, how would I be able to get access to it using python? Thank yu!

also

PowerOfStars wrote:

I am advanced in python
guy if your advanced can i get help with this?
You need to give your token, what I have no idea how t get
You mean your crsftoken thingy? Or your scratch session id?
roketH77
Scratcher
1000+ posts

Python programming language

mrcoat wrote:

mybearworld wrote:

mrcoat wrote:

Hello I'm using python to make something that accesses my scratch messages, but it keeps giving me an access denied thing, how would I be able to get access to it using python? Thank yu!

also

PowerOfStars wrote:

I am advanced in python
guy if your advanced can i get help with this?
You need to give your token, what I have no idea how t get
You mean your crsftoken thingy? Or your scratch session id?
I would assume crsftoken
roketH77
Scratcher
1000+ posts

Python programming language

While True:
   print(bump)
ScratchCatHELLO
Scratcher
1000+ posts

Python programming language

so uh

this is obscure but I don't have an account in a place where anyone is likely to know this

so I'm trying to use SLY (Sly Lex Yacc) to make a “”'programming language“”" in python (you can search the SLY docs for info). the thing is, I keep getting shift-reduce errors even though I've specified the priority of commands. the errors seem to come from my if() implementation.

precedence of tokens (IF is the token for if, obviously)
    # resolve vs shift priority, shift to resolve order
    precedence = (
        ('left', 'ASSIGN', 'PLUSASSIGN', 'MINUSASSIGN', 'TIMESASSIGN', 'DIVASSIGN', 'EXPASSIGN' ),
        ('left', 'EQ', '>', '<' ),
        ('left', 'IF'),
        ('left', '+', '-', 'INCREMENT', 'FACTASSIGN' ),
        ('left', '*', '/'),
        ('left', '^', '!'),
        ('right', 'UMINUS'),
        )

definitions (yes this is sloppy and bad but I have no idea how to make it any better):
    # if attempt (making 27 shift/reduce conflicts somehow)
    # :IF(a==1)a+b
    # if a = 1, it returns b
    @_('IF "(" expr EQ expr ")" expr')
    def expr(self, p):
        if (p.expr0 == p.expr1):
            return p.expr2
        else:
            return 0
    @_('IF "(" expr ">" expr ")" expr')
    def expr(self, p):
        if (p.expr0 > p.expr1):
            return p.expr2
        else:
            return 0
    @_('IF "(" expr "<" expr ")" expr')
    def expr(self, p):
        if (p.expr0 < p.expr1):
            return p.expr2
        else:
            return 0
I highly doubt the definition is causing this, but I'm adding it anyway just in case.

From what I can tell, a shift/reduce error is just when it can't tell weather to resolve what it has or check the next token.
The IF command works fine, so I don't know what the error is.

I'm close to just ignoring the errors because they don't seem to affect anything but I'd like to figure out the cause.

I probably won't get an answer, but it's worth a shot
mybearworld
Scratcher
1000+ posts

Python programming language

Don't know what you are talking about

Powered by DjangoBB