[Tutor] What can I do with this code?

python-tutor@toddmaynard.com python-tutor at toddmaynard.com
Wed Aug 10 10:47:33 CEST 2005


How about changing it into a math quiz program?

You have the program output random problems ("What is 14 * 3 ?")

And then you can output appropriate random insults, words of encouragement, or 
praise as appropriate until the user gets the answer right.   Just be careful 
with division.  You probably don't want to randomly generate a problem like 
("What is 22 / 7 ?") (unless you are going to ask for the remainder too...)  
A trick to get around this problem is to use multiplication to pick a 
dividend.

Psuedocode:

Answer = randomNum
Divisor = randomNum
Dividend = Answer * Divisor

Print "What is (Dividend) / (Divisor) ?"

Have fun....

--Todd

On Tuesday 09 August 2005 07:59 pm, Nathan Pinno wrote:
> I coded the following just for fun:
>
> import random
> cool = ['Cool math!','Awesome!','Way to go!','Happy problem solving!']
> while 1:
>     start = raw_input("Do you want to do some math? Yes or No")
>     if start == "Yes":
>         x = int(raw_input("First number:"))
>         y = int(raw_input("Second number:"))
>         print x*y
>         print random.choice(cool)
>     elif start == "No":
>         break
> print "Goodbye and happy problem solving!"
>
> What can I do with it, other than let it be a fun example of coding?
>
> Nathan
> ---------------------------------------------------------------
> Early to bed,
> Early to rise,
> Makes a man healthy, wealthy, and wise.
> --Benjamin Franklin
> -------------------------------------------------------------------


More information about the Tutor mailing list