Here's a thread I'm starting with my campers taking a PyCamp course.

Yesterday we were co-evolving a calculator driven by looping menu.  It does
squares and square roots (one of the campers supplied this logic) and I was
just getting around to introducing the y^x key as some call it, i.e. any
number to any power, Python's pow(num, exp).

Today we'll pick up where we left off.

We used the shared whiteboard to draw radical signs as I intoned about how
pow(3, 3) means like ```3 * 3 * 3```.  Math Adventures in Python.  We might
also say ```3 ** 3``` (and not ```3^3``` like in so many languages).
sqrt(num) is the same as ```num ** (1/2)``` and we can get the 3rd root of
27 with ```27 ** (1/3)```.

[ Sorry for all the markdown by the way, if you're getting a plaintext
version -- an option I'd advocate for browser based viewers of the archives
someday (to see what it looked like way back when, Before Markdown). ]

So here's what we're up against:  say I want to raise 10 to the 1/3rd
power, same as taking a "cube root" of 10 (tetrahedral whatever).  The menu
prompts:

```python

num = float(input("Your number please: > "))  # yes a bit dangerous
exp = float(input("...and your exponent: > "))  #  user wants to do 1/3
```

Of course that last statement raises an exception because float("1/3")
doesn't work (isn't supposed to). What shall we do then?

I'm thinking we parse anything that looks like a legal fraction and do the
floating point conversion from int(p)/int(q).  We won't allow input like
2.1/3.6 just int/int.  I've already preached against eval() but if it
passes my regular expression test first...

Anyway, it's a discussion.  These are like middle schoolers previewing high
school, at a time when kid focused code schools were under some pressure to
convert to "everything online".  I used to drive to the schools.

We don't have to use a regexp!  A good excuse to say what these are
though.  Or test for the pattern but then use split("/") to pry numerator
from denominator, once we know that'll work?

https://github.com/4dsolutions/python_camp/blob/master/camper_program.py
(snapshot -- part of the camp is they watch me git pushing updates to the
camp repo).

Rather perversely, I may set things back between camps i.e. I'll
deliberately revert the code.

Comments?  Code?

Kirby

PS:  I notice Python 3.8 is being rather more generous in its statistics
module. Campers who wander from the base camp fire are likely to find
themselves staring at pdfs and cdfs.
_______________________________________________
Edu-sig mailing list -- edu-sig@python.org
To unsubscribe send an email to edu-sig-le...@python.org
https://mail.python.org/mailman3/lists/edu-sig.python.org/

Reply via email to