Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
help with making random operators in python
Author Message
silvermatt23

Posted: Wed Feb 06, 2013 8:27 pm   Post subject: help with making random operators in python

im working on a program in pythonthat will generate random numbers and a random math opperator. and then it will solve the the problem. i dont know to generate the opperator though. can some one help?

Sur_real

Posted: Wed Feb 06, 2013 8:34 pm   Post subject: RE:help with making random operators in python

You can just map an unique integer to each operator and generate a random integer which will correspond to that operator.
silvermatt23

Posted: Wed Feb 06, 2013 10:43 pm   Post subject: RE:help with making random operators in python

Thanks, but I don't know how to do that. Can u give me like an example. It will be very helpful thanks
DemonWasp

Posted: Wed Feb 06, 2013 11:36 pm   Post subject: RE:help with making random operators in python

If 0 means "add" and 1 means "subtract", then 2 means...
silvermatt23

Posted: Thu Feb 07, 2013 1:50 am   Post subject: RE:help with making random operators in python

Ok but do they have to be strings or can I just type in 0=+ etc?
Tony

Posted: Thu Feb 07, 2013 1:30 pm   Post subject: RE:help with making random operators in python

What do you think they should be?
Tony's programming blog. DWITE - a programming contest.
rdrake

Posted: Sat Feb 09, 2013 2:18 am   Post subject: Re: help with making random operators in python

This should get you started...

 Python: >>> ops = [lambda x, y: x + y, lambda x, y: x - y] >>> ops[0](5, 5) 10 >>> ops[1](5, 5) 0
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 7 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: