Discuss Scratch

djollieboy11
Scratcher
14 posts

How to do exponents?

I am working on how to make exponents, and I found that their is no exponent block. would somebody be able to help me do this? This is my code so far:
when green flag clicked
forever
set [number one] to (pick random (3) to (10)
set [number two] to (pick random (3) to (10)
set [exponent] to (pick random (0) to (5)
set [sum of exponents and second number] to [number two]
if <not <<[exponent] = [0]> or <[exponent] = [1]>>> then
repeat (exponent)
set [sum of exponents and second number] to ((sum of exponents and second number) * (number two))
end
set [sum of exponents and second number] to ((sum of exponents and second number) / (number two))
set [sum of equation] to ((sum of exponents and second number) * (number one))
else
if <[exponent] = [0]> then
set [sum of equation] to (1)
else
if <[exponent] = [0]> then
set [sum of equation] to ((number one) * (number two))
end
end
end
end

after all of that, I have an ask script that asks the player what the answer is, but I can't add that because the way I entered this didn't have the blocks.
also, this took forever to make, since I had to type this out and learn this new language that is only in the forums.

Last edited by djollieboy11 (March 11, 2025 14:55:20)

Cool_Dude2022
Scratcher
500+ posts

How to do exponents?

djollieboy11 wrote:

I am working on how to make exponents, and I found that their is no exponent block. would somebody be able to help me do this? This is my code so far:
when green flag clicked
forever
set [number one] to (pick random (3) to (10)
set [number two] to (pick random) (3) to (10)
set [exponent] to (pick random) (0) to (5)
set [sum of exponents and second number] to [number two]
if <not <<[exponent] = [0]> or <[exponent] = [1]>>> then
repeat (exponent)
set [sum of exponents and second number] to ((sum of exponents and second number) * (number two))
end
set [sum of exponents and second number] to ((sum of exponents and second number) / (number two))
set [sum of equation] to ((sum of exponents and second number) * (number one))
else
if <[exponent] = [0]> then
set [sum of equation] to (1)
else
if <[exponent] = [0]> then
set [sum of equation] to ((number one) * (number two))
end
end
end
end

after all of that, I have an ask script that asks the player what the answer is, but I can't add that because the way I entered this didn't have the blocks.
also, this took forever to make, since I had to type this out and learn this new language that is only in the forums.
also sorry, I messed up a little in the code.

You mean something like this? Pretty simple to make: https://scratch.mit.edu/projects/1145491233/editor/
NoUsername-King
Scratcher
100+ posts

How to do exponents?

Okay, exponents can be calculated with
([e^ v] of (([ln v] of (base)::operators) * (exponent))::operators)
And root can be calculated with this
([e^ v] of (([ln v] of (base)::operators) / (root))::operators)
djollieboy11
Scratcher
14 posts

How to do exponents?

Okay, thank you all for the help! I really appreciate it.
SuperBee444
Scratcher
2 posts

How to do exponents?

NoUsername-King wrote:

Okay, exponents can be calculated with
([e^ v] of (([ln v] of (base)::operators) * (exponent))::operators)
And root can be calculated with this
([e^ v] of (([ln v] of (base)::operators) / (root))::operators)
I hope you see this, does root mean square root, and if so, square root of what?
NoUsername-King
Scratcher
100+ posts

How to do exponents?

SuperBee444 wrote:

(#5)

NoUsername-King wrote:

Okay, exponents can be calculated with
([e^ v] of (([ln v] of (base)::operators) * (exponent))::operators)
And root can be calculated with this
([e^ v] of (([ln v] of (base)::operators) / (root))::operators)
I hope you see this, does root mean square root, and if so, square root of what?
That can be used for any root, including a square root. A square root would look like this:
([e^ v] of (([ln v] of (base)::operators) / [2])::operators)
and a cube root would be a 3 and so on.
Dan_0319
Scratcher
16 posts

How to do exponents?

NoUsername-King wrote:

Okay, exponents can be calculated with
([e^ v] of (([ln v] of (base)::operators) * (exponent))::operators)
And root can be calculated with this
([e^ v] of (([ln v] of (base)::operators) / (root))::operators)
oh, theres a problem though. how do you do negative bases???
N8_D_GR8_1
Scratcher
1000+ posts

How to do exponents?

Dan_0319 wrote:

-snip-
oh, theres a problem though. how do you do negative bases???
Please avoid posting on other people's topics unless you are helping them. You should create a new topic instead.

Here is a fully functional exponent function that I made:

define (x) ^ (y)
if <(x::custom) > [0]> then
set [EXPONENT: output v] to ([e ^ v] of ((y::custom) * ([ln v] of (x::custom)::operators))::operators)
else
if <(x::custom) < [0]> then
if <(y::custom) = (round (y::custom))> then
set [EXPONENT: output v] to (((1) - ((2) * ((y::custom) mod (2)))) * ([e ^ v] of ((y::custom) * ([ln v] of (() - (x::custom))::operators))::operators))
else
set [EXPONENT: output v] to [NaN]
end
else
if <(y::custom) < [0]> then
set [EXPONENT: output v] to [NaN]
else
set [EXPONENT: output v] to (() + <(y::custom) = [0]>)
end
end
end

EDIT: I had to make so many edits to find what Scratch thought was inappropriate language. Apparently “p l e a s e d o n o t p o s t…” is unsuitable language? Man, Scratch really needs to fix the filter.

Last edited by N8_D_GR8_1 (Oct. 31, 2025 14:30:04)

dspace1015
Scratcher
17 posts

How to do exponents?

Dan_0319 wrote:

oh, theres a problem though. how do you do negative bases???
Look at my response to this discussion if you need to do negative bases.
DuraeMan
Scratcher
1 post

How to do exponents?

N8_D_GR8_1 wrote:

Dan_0319 wrote:

-snip-
oh, theres a problem though. how do you do negative bases???
Please avoid posting on other people's topics unless you are helping them. You should create a new topic instead.

Here is a fully functional exponent function that I made:

define (x) ^ (y)
if <(x::custom) > [0]> then
set [EXPONENT: output v] to ([e ^ v] of ((y::custom) * ([ln v] of (x::custom)::operators))::operators)
else
if <(x::custom) < [0]> then
if <(y::custom) = (round (y::custom))> then
set [EXPONENT: output v] to (((1) - ((2) * ((y::custom) mod (2)))) * ([e ^ v] of ((y::custom) * ([ln v] of (() - (x::custom))::operators))::operators))
else
set [EXPONENT: output v] to [NaN]
end
else
if <(y::custom) < [0]> then
set [EXPONENT: output v] to [NaN]
else
set [EXPONENT: output v] to (() + <(y::custom) = [0]>)
end
end
end

EDIT: I had to make so many edits to find what Scratch thought was inappropriate language. Apparently “p l e a s e d o n o t p o s t…” is unsuitable language? Man, Scratch really needs to fix the filter.

N8_D_GR8_1 wrote:

Dan_0319 wrote:

-snip-
oh, theres a problem though. how do you do negative bases???
Please avoid posting on other people's topics unless you are helping them. You should create a new topic instead.

Here is a fully functional exponent function that I made:

define (x) ^ (y)
if <(x::custom) > [0]> then
set [EXPONENT: output v] to ([e ^ v] of ((y::custom) * ([ln v] of (x::custom)::operators))::operators)
else
if <(x::custom) < [0]> then
if <(y::custom) = (round (y::custom))> then
set [EXPONENT: output v] to (((1) - ((2) * ((y::custom) mod (2)))) * ([e ^ v] of ((y::custom) * ([ln v] of (() - (x::custom))::operators))::operators))
else
set [EXPONENT: output v] to [NaN]
end
else
if <(y::custom) < [0]> then
set [EXPONENT: output v] to [NaN]
else
set [EXPONENT: output v] to (() + <(y::custom) = [0]>)
end
end
end

EDIT: I had to make so many edits to find what Scratch thought was inappropriate language. Apparently “p l e a s e d o n o t p o s t…” is unsuitable language? Man, Scratch really needs to fix the filter.

But how do you do negative bases with multiple decimals?'

edit - wanted to remove this reply after reading your response to the topic properly, but cant, will make my own topic next time

EDIT 2 - I figured everything out but hoooow doo i deeellleeetttee pooosssts

Last edited by DuraeMan (Nov. 12, 2025 19:58:55)

N8_D_GR8_1
Scratcher
1000+ posts

How to do exponents?

DuraeMan wrote:

-snip-
But how can you make it works with bases that are negative and have multiple decimals?
I'll say it again, please avoid posting on other people's topics unless you are helping them. Create a new topic instead. Your post will actually be more likely to be answered if you create a new topic. This function that I provided does work with decimals and negatives in both the base and the exponent. Just try it out
N8_D_GR8_1
Scratcher
1000+ posts

How to do exponents?

DuraeMan wrote:

EDIT 2 - I figured it out but hoooow doo i deeellleeetttee pooosssts
It's ok. We all make mistakes (myself included).

Powered by DjangoBB