[Tutor] SOME KNOWLEDGE OF IRONPYTHON?

2012-02-26 Thread JOSEPH MARTIN MPALAKA
Hullo to you All,
Has any one used IronPython studio from microsoft Visual Studio.

Am so new into IronPython please.

It’s missing a help menu Tutorial link of "HOW TO" along the menu bar,
so as to be used in learning and knowing how make out something. Could
one be able to structure for me this code in IronPython OR, to find me
any other tutorial documentation of designing the above interfaces in
IronPython studio?


joseph





-- 
MY BEING was HIS BEING.  Of what is magnificent and liked of me, this
was him too. In VAIN, I will always miss u,thou i live with YOU in
vain.
   Lt.Col.Sam .E. Lukakamwa  (DADDY)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SOME KNOWLEDGE OF IRONPYTHON?

2012-02-26 Thread Steven D'Aprano

JOSEPH MARTIN MPALAKA wrote:

Hullo to you All,
Has any one used IronPython studio from microsoft Visual Studio.

Am so new into IronPython please.

It’s missing a help menu Tutorial link of "HOW TO" along the menu bar,
so as to be used in learning and knowing how make out something. Could
one be able to structure for me this code in IronPython OR, to find me
any other tutorial documentation of designing the above interfaces in
IronPython studio?


This is a mailing list for learning Python the language, not specific features 
of individual implementations.


Unfortunately, we have a bias here for CPython over Jython, IronPython, PyPy, 
Stackless, and other even lesser-known versions of Python. This bias is due to 
familiarity, not because we don't like the other implementations.


You may be better off asking your question on a dedicated IronPython mailing 
list or forum:


http://lists.ironpython.com/listinfo.cgi
http://ironpython.net/support/


Good luck!



--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SOME KNOWLEDGE OF IRONPYTHON?

2012-02-26 Thread Alan Gauld

On 26/02/12 11:07, JOSEPH MARTIN MPALAKA wrote:


It’s missing a help menu Tutorial link of "HOW TO" along the menu bar,
so as to be used in learning and knowing how make out something. Could
one be able to structure for me this code in IronPython OR, to find me
any other tutorial documentation of designing the above interfaces in
IronPython studio?



A quick Google throws up several tutorials/manuals.

Here is one that looked promising:

http://www.ironpython.info/index.php/Contents

You are welcome to asks questions about Python here, but I don't know if 
we have many IronPython users so questions about VisualStudio aspects 
are probably better handled on a more specific forum.



--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with Python Program

2012-02-26 Thread Carolina Dianne LaCourse
First off I want to really thank you for all of the help! I am in my
first semester as I started as a non traditional student in January.
Even though I am in an intro class I think that many of my class mates
had more of a c/s foundation in high then I did. It took me a few
tries but I did finally get my program to run using this code :)

#import random target = random.randint(1,100)

import random #import random number generator module
target = random.randint(1,100) #generates random number between 1 and 100
guess = float(raw_input('pick a number between 1 and 100'))
while guess != target:
if guess < target: print 'too low'
elif guess > target: print 'too high'
#otherwise guess == target and game is over

I am having trouble getting it to run for more than one game but am
trying. Also I started off using the idle shell to write the codes but
it wont let you run it from there, so I opened a new window and
retyped it for my first few attempts. I am unsure why you would use
the idle shell if you would need to open a new window and retype it
anyway. Is there an easier way or something that I am not getting?
After doing that several times I just opened a new window and started
from there without using the shell and it worked fine, so can I always
do it that way and not use the shell at all?  I am also still kind of
unsure about the loops and was hoping you could explain a little more
about it or may know of a good online resource? Thanks again for all
the help...Steve really helped by explaining it simply to me and I
really appreciate it! It took me like 10-15 tries but I was so excited
when I finally got it to run!


On 2/24/12, Steven D'Aprano  wrote:
> Carolina Dianne LaCourse wrote:
>
> [...]
>> I understand that I need to ask for raw input from the user and that I
>> need to be able to use the if elif else to tell the user whether their
>> number matches or id too high or to low but am just not sure what to
>> do first. Any advice would be greatly appreciated! I have tried some
>> online tutorials to get the basics but still am having a really hard
>> time. I did work with scratch a bit earlier this semester and got
>> that, but am really struggling with python.
>
> Start by writing down in plain English the steps of how you would play the
> guessing game. This is a called an algorithm, which is something very
> similar
> to a recipe or a set of instructions. You might have something like this:
>
> (1) Think of a number between 1 and 100, and remember it.
> (2) Repeat the following steps until the game is over:
> (3) - Ask the person playing for a number between 1 and 100.
> (4) - If the number is too low, tell them it is too low.
> (5) - If the number is too high, tell them it is too high.
> (6) - If the number is equal to the number you thought of, the game is over.
>
> All that makes up *one* game. Then you need instructions to play multiple
> games:
>
> (a) Play one game, as above.
> (b) Repeat the following steps until done:
> (c) - Ask the player if they want to play again.
> (d) - If they say Yes, play one game, as above.
> (e) - Otherwise, we are done.
> (f) Finally, print how many games were played, how many guesses were needed,
> and the average number of guesses per game.
>
>
> Now, you need to change the English instructions to instructions the
> computer
> can follow, using Python. For example, Step (1) above picks a random number
> and remembers it as the target of the game:
>
> import random
> target = random.randint(1, 100)
>
> Step (2) is a bit harder -- it's a loop. You should have learned about while
> loops and for loops. I expect a while loop is better for this, because you
> can't tell ahead of time how many times you need to go round and round the
> loop.
>
>
> while guess != target:
>  Step (3) ask the user for a number, and call it "guess"
>  if guess < target:
>  print "too low"
>  elif guess > target:
>  print "too high"
>  # otherwise guess == target so the game will be over
>
>
> Notice that this isn't exactly Python code. The most obvious problem is the
> line "Step (3)..." which is plain English. You need to replace that with
> code
> to actually ask the user for a number. (Hint: you will need the raw_input
> function.)
>
> Another problem is that the *first* time you enter the loop, the name
> "guess"
> isn't defined. You need to give it a value to start with, before the loop.
> Any
> value will do, so long as it isn't target. I suggest 0.
>
> Does this help you get started? Go ahead and write some code, and see where
> it
> takes you. Piece by piece, step by step, you should work towards replacing
> each bit of English instruction with some Python code to do that.
>
> You should aim to write code to play *one* game first. Get that right,
> first,
> then adapt it to play multiple games.
>
> Write some code, see how it works (or where is fails to work), and anything
> that is unclear, come back and ask.

Re: [Tutor] Help with Python Program

2012-02-26 Thread Robert Sjoblom
> import random #import random number generator module
> target = random.randint(1,100) #generates random number between 1 and 100
> guess = float(raw_input('pick a number between 1 and 100'))
> while guess != target:
>    if guess < target: print 'too low'
>    elif guess > target: print 'too high'
>    #otherwise guess == target and game is over
>
> I am having trouble getting it to run for more than one game but am
> trying. Also I started off using the idle shell to write the codes but
> it wont let you run it from there, so I opened a new window and
> retyped it for my first few attempts. I am unsure why you would use
> the idle shell if you would need to open a new window and retype it
> anyway.
[snip]
> so can I always
> do it that way and not use the shell at all?

The shell is for testing out things; it's not really for writing
entire programs in. But as a test-tool it's priceless. Don't know what
random.randint() does? Use the shell to find out. Want to see if you
can convert ints to floats? Use the shell. It's a great way to test
short things like that, because it will give you instant feedback. You
can write longer code in it, but it can be cumbersome. In the end,
it's another tool for your belt, I guess you could say.

> I am also still kind of
> unsure about the loops and was hoping you could explain a little more
> about it or may know of a good online resource?

The while loop you're using tests for one thing: is guess == target.
If it isn't, the contents of the while loop executes. I should note
that while your loop works, it doesn't work as intended: what happens
if you guess too low? Let's see how the program runs:

computer picks a number between 1 and 100 and stores it in variable 'target'
computer then asks user for a number between 1 and 100 and stores it
in variable 'guess'
while loop checks whether guess is the same as target.
If it's not, it checks if the guess is higher than target or lower
than target and then prints the corresponding response.
the while loop checks again if guess == target. It's not, since we
never change the value of guess.
It checks if the guess is higher than target or lower than target...(etc)
the while loop checks again...

In short, you can say that the loop is named because of its behaviour:
it loops until it shouldn't any longer.

I'm sure you can see the problem here. So, while you now can check
whether a variable is equal to another variable, you currently have no
way to change 'guess' for a new try. Can you think of any way to solve
that?

And while this might not be entirely on topic, there's a wonderful
book for complete beginners -- I've used it as well -- that I'd like
to recommend: Python Programming for the Absolute Beginner. In fact,
one of the excercises happen to be this particular game.

--
best regards,
Robert S.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] roman to arabic

2012-02-26 Thread Sukhpreet Sdhu
Hi
I just wrote python code to convert roman to arabic numerals, but its not 
working.
Can you just check where the problem is and way to correct that.
So here is my python code
import string
print "Welcome to the numeric conversion program"
print "Please enter command"
data=raw_input()
now = 0
previous = 0
total = 0
if data == "r":
    print "Enter roman numeric to convert in arabic"
    roman_numeric=string.swapcase(raw_input("Enter the Roman Numeral to convert 
to arabic"))
 if roman_numeric == ("M" or "D" or "L" or "C" or "L" or "X" or "V" or 
"I"):
 
 Length = len(roman_numeric) - 1
 i = roman_numeric[Length]
 if i == "M":
 now = 1000
 if i == "D":
 now = 500
 if i == "C":
 now = 100
 if i == "L":
 now = 50
 if i == "X":
 now = 10
 if i == "V":
 now = 5
 if i == "I":
 now = 1
 acc = now
 if (previous >= now):
 total += acc-prvious
 print "The total is",total
 if (previous <= now):
 total += acc-prevous
 print "The total is",total
 else :
 if data == "a" :
 print "Arabic number to 
convert"

   thanks
sukhpreet sidhu 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] roman to arabic

2012-02-26 Thread Mark Lawrence

On 26/02/2012 23:29, Sukhpreet Sdhu wrote:

Hi
I just wrote python code to convert roman to arabic numerals, but its not 
working.
Can you just check where the problem is and way to correct that.
So here is my python code
import string
print "Welcome to the numeric conversion program"
print "Please enter command"
data=raw_input()
now = 0
previous = 0
total = 0
if data == "r":
 print "Enter roman numeric to convert in arabic"
 roman_numeric=string.swapcase(raw_input("Enter the Roman Numeral to convert to 
arabic"))
  if roman_numeric == ("M" or "D" or "L" or "C" or "L" or "X" or "V" or "I"):
  Length = len(roman_numeric) - 1
  i = roman_numeric[Length]
  if i == "M":
  now = 1000
  if i == "D":
  now = 500
  if i == "C":
  now = 100
  if i == "L":
  now = 50
  if i == "X":
  now = 10
  if i == "V":
  now = 5
  if i == "I":
  now = 1
  acc = now
  if (previous>= now):
  total += acc-prvious
  print "The total is",total
  if (previous<= now):
  total += acc-prevous
  print "The total is",total
  else :
  if data == "a" :
  print "Arabic number to 
convert"

thanks
sukhpreet sidhu
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



I'm sorry but the code is so badly formatted via Thunderbird that it's 
pretty much impossible to work out what you intend.  Try resending with 
the code correctly formatted.  Also put print statements into the code 
so that you can follow the flow and see what it's doing, then you'll be 
able to make some progress yourself.


--
Cheers.

Mark Lawrence.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] roman to arabic

2012-02-26 Thread Walter Prins
Hi ,

On 26 February 2012 23:29, Sukhpreet Sdhu  wrote:
> Hi
> I just wrote python code to convert roman to arabic numerals, but its not 
> working.
How exactly is it not working?  Please don't make us guess or work
more than neccesary trying to help you...


> Can you just check where the problem is and way to correct that.
> So here is my python code
> import string
> print "Welcome to the numeric conversion program"
> print "Please enter command"
> data=raw_input()
> now = 0
> previous = 0
> total = 0
> if data == "r":
>     print "Enter roman numeric to convert in arabic"
>     roman_numeric=string.swapcase(raw_input("Enter the Roman Numeral to 
> convert to arabic"))
>  if roman_numeric == ("M" or "D" or "L" or "C" or "L" or "X" or "V" or "I"):
>  Length = len(roman_numeric) - 1
>  i = roman_numeric[Length]
>  if i == "M":
>  now = 1000
>  if i == "D":
>  now = 500
>  if i == "C":
>  now = 100
>  if i == "L":
>  now = 50
>  if i == "X":
>  now = 10
>  if i == "V":
>  now = 5
>  if i == "I":
>  now = 1
>  acc = now
>  if (previous >= now):
>  total += acc-prvious
>  print "The total is",total
>  if (previous <= now):
>  total += acc-prevous
>  print "The total is",total
>  else :
>  if data == "a" :
>  print "Arabic number to 
> convert"
>
>    thanks
> sukhpreet sidhu

Is your code really indented like that?  A quote worth mentioning here
is:  "If you need more than 3 levels of indentation, you're screwed
anyway, and should fix your program." --  Linus Torvalds

Now he was writing w.r.t. C/C++ but the principle holds for Python
also in general -- very highly nested levels of indentation are
indicative of some kind of program problem, and will likely cause you
to conceptually lose control of what the code's supposed to be doing.

Can you please explain in english (pseudocode) your algorithm for
converting a roman numeral string to arabic numbers, with a more
direct explanation of what you've tried and how your solution is not
working from what you're expecting.  Then we'll be able to help you
better and will not be left having to guess at how

All that said, apart from the indentation weirdness, a few more
offhand observations: I can see 3 different spellings for "previous"
in the code, which will obviously cause problems.  The logic to deal
with smaller numbers preceding larger numbers seem broken (though I've
not looked too closely).  The conditions both include equality (>= and
<=) which is likely wrong, the indentation is wrong and both
conditions seem to be doing the same thing, which must likewise be
wrong.  (You'd expect there to be some difference in handling the case
when the previous number is smaller that the current number vs when
it's larger...)

HTH,

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] roman to arabic

2012-02-26 Thread Alan Gauld

On 26/02/12 23:29, Sukhpreet Sdhu wrote:


import string


Are you using a very old versioon opf python?
If not you should not use string.
The built in string methods can do everything you
want without resorting to string.


print "Welcome to the numeric conversion program"
print "Please enter command"
data=raw_input()
now = 0
previous = 0
total = 0
if data == "r":
 print "Enter roman numeric to convert in arabic"
 roman_numeric=string.swapcase(raw_input("Enter the Roman Numeral to convert to 
arabic"))


Are you sure you want swapcase()? I'd have thought uppercase()
would be more effective given the tests below.

Using built in methods that line becomes:

roman_numeric=raw_input("Enter the Roman Numeral to convert to 
arabic").uppercase()




  if roman_numeric == ("M" or "D" or "L" or "C" or "L" or "X" or "V" or "I"):


This is just wrong!
The parenthesised list will evaluate to True so you are testing  if the 
variable is True, which it will be if not empty.


You want:

if roman_numeric in ("M","D","L","C","L","X","V","I"):


  Length = len(roman_numeric) - 1


If the variable is one of the items in your list it is only 1 char long 
so you re setting Length to zero. Is that what you want?



  i = roman_numeric[Length]


If you really want to extract the last digit use a -1 index.
In which case you dshould do the same for the check on valid values...



  if i == "M":
  now = 1000
  if i == "D":
  now = 500


Are you sure you want this structure?
It would look a lot neater using elif

   if i == "M":
   now = 1000
   elif i == "D":
   now = 500
   elif i == "C":
now = 100

But better still would be to use a dictionary:

values = { 'I':1, 'V':5, 'X':10,...'D':500, 'M':1000 }

now = values[i]


  acc = now
  if (previous>= now):
  total += acc-prvious


spelling error in prvious


  print "The total is",total
  if (previous<= now):
  total += acc-prevous
  print "The total is",total
  else :


This else doesn't line up with any if.

>   if data == "a" :

else:
   if :

could just be

elif :

HTH,

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] roman to arabic

2012-02-26 Thread bob gailer

On 2/26/2012 6:29 PM, Sukhpreet Sdhu wrote:

Hi
I just wrote python code to convert roman to arabic numerals

[snip] Yuk what a  mess.

May I suggest you start with a much simpler program, which is to take a 
roman number between 1 and 3 (just i's) and convert that.


First describe how you'd convert the number by hand. Then convert that 
process to Python.


Test the program. Fix any problems. Report back to us success or a 
problem you don't know how to address. Tell us exactly what went wrong. 
(e.g. I entered iii expecting 3 and got 17 or if you get a traceback 
post it. For example when I run your program I get:


Traceback (  File "", line 12
if roman_numeric == ("M" or "D" or "L" or "C" or "L" or "X" or "V" 
or "I"):

  ^
IndentationError: unindent does not match any outer indentation level

Then add v (now the number is between 1 and 8).

You will come up with a completely different program! And it will be the 
correct one.


Also provide meaningful prompts.

print "Please enter command"

If I was running your program and saw that I'd have to give up since I 
have no idea what is expected.


print "Please enter command - r for roman-arabic"

would be much better.

--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor