Re: [Tutor] guess my number game

2018-05-09 Thread Alan Gauld via Tutor
   On 9 May 2018 2:30 am, Kerri Murphy  wrote:

 Hi there,
 Yes, the first code does a good job by asking them to go higher or lower
 after each guess, in the pop up window.

   My point is that the code you posted can't even run, let alone do a good
   job. The indentation is all messed up and will yield errors.

 The 2nd code works, but only outputs all the higher and lower outputs
 after the 10 guesses.

   How are you running the code?
   Are you using the interactive prompt to type it in? Are you running it in
   an ide like idle?
   If you put it in a file and run it from the OS command line the second
   version should more or less work.

 point, but we just wanted the game to tell the user if he should go
 lower or higher after every guess.
 Does this make sense?

   Yes and your code should do that if you put it in a file. If you try
   typing it at the python prompt you may well get the result you describe.
   Alan g.

 On Tue, May 8, 2018 at 6:18 PM, Alan Gauld <[1]alan.ga...@yahoo.co.uk>
 wrote:

   The first block of code is full of errors and couldn't work so I have
   no idea what you were really doing!

The second block should kind of work. From your description I'd guess
   you have an indentation error such that most of the code that should
   be inside the loop is being bypassed. Are you sure the code you sent
   us exactly what you are running?

   Alan g

   On 8 May 2018, at 10:39, Kerri Murphy <[2]kmur...@easton.k12.ma.us>
   wrote:

   My students are creating a guess my number game.

   They are trying to take this type of code (the flow of it), and turn
   it
   into a code using a while loop.
   Here is the first code

   n = int(input('Guess my number: '))if (n <= 172 and n >= 174):
   print('Correct')elif (n >= 174):
   a = int(input('Go Down'))
   if (a >= 174):
   c = int(input('Go Down'))
   if (c >= 174):
   g = int(input('Last Guess Go Down'))
   if (g == 173):
   print('Correct')
   elif (c <= 172):
   i = int(input('Last Guess Go Up'))
   if (i == 173):
   print('Correct')
   else:
   print('Correct')
   elif (a <= 172):
   e = int(input('Go up'))
   if (e >= 174):
   f = int(input('Last Guess Go Down'))
   if (f == 173):
   print('Correct')
   elif (e <= 172):
   h = int(input('Last Guess Go Up'))
   if (h == 173):
   print('Correct')
   else:
   print('Correct')
   else:
   print('Correct')elif (n <= 172):
   b = int(input('Go Up'))
   if (b >= 174):
   d = int(input('Go Down'))
   if (d >= 174):
   j = int(input('Last Guess Go Down'))
   if (j == 173):
   print('Correct')
   elif (d <= 172):
   m = int(input('Last Guess Go Up'))
   if (m == 173):
   print('Correct')
   else:
   print('Correct')
   elif (b <= 172):
   e = int(input('Go Up'))
   if (e >= 174):
   k = int(input('Last Guess Go Down'))
   if (k == 173):
   print('Correct')
   elif (e <= 172):
   l = int(input('Last Guess Go Up'))
   if (l == 173):
   print('Correct')
   else:
   print('Correct')
   else:
   print('Correct')else:
   print('Correct')

   Here is the code with the while loop
   import random
   n = (random.randint(0,100))
   g = int(input('Guess my number, 0 to 100, you have 10 chances'))
   c = 0
   while (c < 10):
   g = int(input('Guess my number, 0 to 100, you have 10 chances'))
   c = c + 1
   if (g >= n):
   print('Lower!')
   elif (g <= n):
   print('Higher!')
   elif (g == n):
   break
   if (g == n):
   print('You guess my number! It took you ' + str(c) + ' tries!')

   Everyone's code just keeps asking for numbers without giving feedback,
   except for the longer code above.

   Can you help us consolidate the code?  We are using random.randint.

   Thank you!
   ___
   Tutor maillist  -  [3]Tutor@python.org
   To unsubscribe or change subscription options:
   [4]https://mail.python.org/mailman/listinfo/tutor

References

   Visible links
   1. mailto:alan.ga...@yahoo.co.uk
   2. mailto:kmur...@easton.k12.ma.us
   3. mailto:Tutor@pytho

Re: [Tutor] calling printf() in a C language DLL using ctypes.CDLL

2018-05-09 Thread James Chapman
A long time ago when I was working with Python and DLLs I slapped together
a basic and ugly example.
You can find it here: https://github.com/James-Chapman/python-code-snippets/
tree/master/DLL_C_funcs_w_callbacks

The whole thing should load into Visual Studio. I can't guarantee that it
works in its current state though. It was created mainly as a reminder to
myself.

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


Re: [Tutor] calling printf() in a C language DLL using ctypes.CDLL

2018-05-09 Thread Brad M
Hmmm, I guess then it's time for me to ask this question: Is how I do this
the way you do it?

I have been inserting lines like this:   print("The program got here!")
all over my python code whenever I want to know where the program went.

If you want to know where your program went when something went wrong or
when it triggers a if condition, how do you do it?

Thanks!



On Wed, May 9, 2018 at 8:16 AM, eryk sun  wrote:

> On Tue, May 8, 2018 at 9:39 AM, Brad M  wrote:
> >
> > I compile this by typing this in the command line:
> > cl /LD /I C:\python\include helloworld.c C:\python\libs\python36.lib
>
> You're not using Python's C API, so you only need `cl /LD helloworld.c`.
>
> > However, this doesn't print anything on the python window.
> > What I would like is to do is to be able to use printf() in my .dll
> > by having the c code pop up a console window to print or
> > to have something that can print() in the python window somehow.
>
> By Python window, do you mean the IDLE GUI? If the library is loaded
> in a GUI program in which stdout is invalid, it will have to manually
> allocate a console via `AllocConsole` and open the screen buffer using
> the reserved filename "CONOUT$". Then it can print to the opened FILE
> stream using fprintf(). But I'll reiterate Alan here that this would
> be unusual behavior for a shared library, unless it's specifically
> intended as a UI library.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] guess my number game

2018-05-09 Thread Kerri Murphy
Hi there,

Yes, the first code does a good job by asking them to go higher or lower
after each guess, in the pop up window.

The 2nd code works, but only outputs all the higher and lower outputs after
the 10 guesses.  Everyone in the class has the same result basically.  When
I searched on various sites, they also work this way.  I can allow them to
be finished at this point, but we just wanted the game to tell the user if
he should go lower or higher after every guess.

Does this make sense?

Thank you,
Kerri

On Tue, May 8, 2018 at 6:18 PM, Alan Gauld  wrote:

> The first block of code is full of errors and couldn't work so I have no
> idea what you were really doing!
>
>  The second block should kind of work. From your description I'd guess you
> have an indentation error such that most of the code that should be inside
> the loop is being bypassed. Are you sure the code you sent us exactly what
> you are running?
>
> Alan g
>
> On 8 May 2018, at 10:39, Kerri Murphy  wrote:
>
> My students are creating a guess my number game.
>
> They are trying to take this type of code (the flow of it), and turn it
> into a code using a while loop.
> Here is the first code
>
> n = int(input('Guess my number: '))if (n <= 172 and n >= 174):
> print('Correct')elif (n >= 174):
> a = int(input('Go Down'))
> if (a >= 174):
> c = int(input('Go Down'))
> if (c >= 174):
> g = int(input('Last Guess Go Down'))
> if (g == 173):
> print('Correct')
> elif (c <= 172):
> i = int(input('Last Guess Go Up'))
> if (i == 173):
> print('Correct')
> else:
> print('Correct')
> elif (a <= 172):
> e = int(input('Go up'))
> if (e >= 174):
> f = int(input('Last Guess Go Down'))
> if (f == 173):
> print('Correct')
> elif (e <= 172):
> h = int(input('Last Guess Go Up'))
> if (h == 173):
> print('Correct')
> else:
> print('Correct')
> else:
> print('Correct')elif (n <= 172):
> b = int(input('Go Up'))
> if (b >= 174):
> d = int(input('Go Down'))
> if (d >= 174):
> j = int(input('Last Guess Go Down'))
> if (j == 173):
> print('Correct')
> elif (d <= 172):
> m = int(input('Last Guess Go Up'))
> if (m == 173):
> print('Correct')
> else:
> print('Correct')
> elif (b <= 172):
> e = int(input('Go Up'))
> if (e >= 174):
> k = int(input('Last Guess Go Down'))
> if (k == 173):
> print('Correct')
> elif (e <= 172):
> l = int(input('Last Guess Go Up'))
> if (l == 173):
> print('Correct')
> else:
> print('Correct')
> else:
> print('Correct')else:
> print('Correct')
>
>
>
> Here is the code with the while loop
> import random
> n = (random.randint(0,100))
> g = int(input('Guess my number, 0 to 100, you have 10 chances'))
> c = 0
> while (c < 10):
> g = int(input('Guess my number, 0 to 100, you have 10 chances'))
> c = c + 1
> if (g >= n):
> print('Lower!')
> elif (g <= n):
> print('Higher!')
> elif (g == n):
> break
> if (g == n):
> print('You guess my number! It took you ' + str(c) + ' tries!')
>
>
> Everyone's code just keeps asking for numbers without giving feedback,
> except for the longer code above.
>
> Can you help us consolidate the code?  We are using random.randint.
>
> Thank you!
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] guess my number game

2018-05-09 Thread Kerri Murphy
Perhaps the indentation was changed when I copy and pasted it, but also
we've only been using codeskulptor to run our answers.   That code did work
on ours, so that is weird.  But yes there are a lot of errors.

We just type it into code skulptor and press play.  A box pops up for any
user input.  The display is covered by the box, so you can't see any
results as you are guessing.

We will still be trying to work on this code.   We will try the file option
you suggested.  We don't have access to the OS at school...

Thank you,
Kerri

On Wed, May 9, 2018 at 3:38 AM, Alan Gauld  wrote:

>
>
> On 9 May 2018 2:30 am, Kerri Murphy  wrote:
>
> Hi there,
>
> Yes, the first code does a good job by asking them to go higher or lower
> after each guess, in the pop up window.
>
>
> My point is that the code you posted can't even run, let alone do a good
> job. The indentation is all messed up and will yield errors.
>
>
> The 2nd code works, but only outputs all the higher and lower outputs
> after the 10 guesses.
>
> How are you running the code?
> Are you using the interactive prompt to type it in? Are you running it in
> an ide like idle?
>
> If you put it in a file and run it from the OS command line the second
> version should more or less work.
>
>
>
> point, but we just wanted the game to tell the user if he should go lower
> or higher after every guess.
>
> Does this make sense?
>
>
>
> Yes and your code should do that if you put it in a file. If you try
> typing it at the python prompt you may well get the result you describe.
>
> Alan g.
>
>
>
>
>
> On Tue, May 8, 2018 at 6:18 PM, Alan Gauld  wrote:
>
> The first block of code is full of errors and couldn't work so I have no
> idea what you were really doing!
>
>  The second block should kind of work. From your description I'd guess you
> have an indentation error such that most of the code that should be inside
> the loop is being bypassed. Are you sure the code you sent us exactly what
> you are running?
>
> Alan g
>
> On 8 May 2018, at 10:39, Kerri Murphy  wrote:
>
> My students are creating a guess my number game.
>
> They are trying to take this type of code (the flow of it), and turn it
> into a code using a while loop.
> Here is the first code
>
> n = int(input('Guess my number: '))if (n <= 172 and n >= 174):
> print('Correct')elif (n >= 174):
> a = int(input('Go Down'))
> if (a >= 174):
> c = int(input('Go Down'))
> if (c >= 174):
> g = int(input('Last Guess Go Down'))
> if (g == 173):
> print('Correct')
> elif (c <= 172):
> i = int(input('Last Guess Go Up'))
> if (i == 173):
> print('Correct')
> else:
> print('Correct')
> elif (a <= 172):
> e = int(input('Go up'))
> if (e >= 174):
> f = int(input('Last Guess Go Down'))
> if (f == 173):
> print('Correct')
> elif (e <= 172):
> h = int(input('Last Guess Go Up'))
> if (h == 173):
> print('Correct')
> else:
> print('Correct')
> else:
> print('Correct')elif (n <= 172):
> b = int(input('Go Up'))
> if (b >= 174):
> d = int(input('Go Down'))
> if (d >= 174):
> j = int(input('Last Guess Go Down'))
> if (j == 173):
> print('Correct')
> elif (d <= 172):
> m = int(input('Last Guess Go Up'))
> if (m == 173):
> print('Correct')
> else:
> print('Correct')
> elif (b <= 172):
> e = int(input('Go Up'))
> if (e >= 174):
> k = int(input('Last Guess Go Down'))
> if (k == 173):
> print('Correct')
> elif (e <= 172):
> l = int(input('Last Guess Go Up'))
> if (l == 173):
> print('Correct')
> else:
> print('Correct')
> else:
> print('Correct')else:
> print('Correct')
>
>
>
> Here is the code with the while loop
> import random
> n = (random.randint(0,100))
> g = int(input('Guess my number, 0 to 100, you have 10 chances'))
> c = 0
> while (c < 10):
> g = int(input('Guess my number, 0 to 100, you have 10 chances'))
> c = c + 1
> if (g >= n):
> print('Lower!')
> elif (g <= n):
> print('Higher!')
> elif (g == n):
> break
> if (g == n):
> print('You guess my number! It took you ' + str(c) + ' tries!')
>
>
> Everyone's code just keeps asking for numbers without giving feedback,
> except for the longer code above.
>
> Can you help us consolidate the code?  We are using random.randint.
>
> Thank you!
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>
>
>
___
Tutor ma

[Tutor] Choice of tools

2018-05-09 Thread Brad M
Hi all, I have a question about how to choose a proper IDE for C/C++

I have been using visual studio ever since my C++ 101 days, but now I
realized there is a problem: feature lock-in!

As an aside, I can't get "Error squiggles" to show up in my .c project in
visual studio 2017, where as in my .cpp project it promptly notifies me
of anything it doesn't like, such as printff("Hello world! \n );
Anyone know how to make it work for .c?

So I have been happily letting MS VS 2017 community do my thinking
for me, so to speak, when it comes to error checking. Now I found out
I can't do any work since there isn't that Error squiggles feature for me,
I have to hunt down my next IDE!

Well, Notepad++ has this really cool "VIM dark blue" theme that is
gorgeous! However, I am a lose for choosing my next editor/IDE...


1) is it ok to get used to a feature that only some products feature
2) is there anything else that has Error squiggles?
3) recommend a C/C++ editor?

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


[Tutor] Append to list

2018-05-09 Thread Rick Jaramillo

Hello,

I’m having trouble understanding the following behavior and would greatly 
appreciate any insight. 

l = [1,2,3,4]
b=[]

for i in range(l):
print l
b.append(l)
l.pop(0)

print b


OUTPUT 
[1,2,3,4]
[2,3,4]
[3,4]
[4]
[[],[],[],[]]

My confusions is the output for b. I don’t understand why it’s empty. I’m 
expecting for b to equal [[1,2,3,4], [2,3,4], [3,4], [4]].  

Best Regards,
Rick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of tools

2018-05-09 Thread Ben Finney
Brad M  writes:

> Hi all, I have a question about how to choose a proper IDE for C/C++

You will likely get better-informed advice from a forum specific to C
and C++, then. This forum is for people learning Python.

-- 
 \  “If you don't fail at least 90 percent of the time, you're not |
  `\aiming high enough.” —Alan Kay |
_o__)  |
Ben Finney

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


Re: [Tutor] Append to list

2018-05-09 Thread Alan Gauld via Tutor


On 9 May 2018, at 23:57, Rick Jaramillo  wrote:

>
>Hello,
>I’m having trouble understanding the following behavior and would greatly 
>appreciate any insight. 
>l = [1,2,3,4]
>b=[]
>for i in range(l):
>    print l
>    b.append(l)
>    l.pop(0)
>print b
>OUTPUT 
>[1,2,3,4]
>[2,3,4]
>[3,4]
>[4]
>[[],[],[],[]]
>My confusions is the output for b. I don’t understand why it’s empty. I’m 
>expecting for b to equal [[1,2,3,4], [2,3,4], [3,4], [4]].  

You append l each time. The same l, not a copy of its current state. You also 
modify l each time. But there is only one list object. It is just being 
referenced from several places. So all of the references reflect your changes.


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


Re: [Tutor] Choice of tools

2018-05-09 Thread Alan Gauld via Tutor


On 9 May 2018, at 23:54, Brad M  wrote:

>
>As an aside, I can't get "Error squiggles" to show up in my .c project in
>visual studio 2017, where as in my .cpp project it promptly notifies me

I don't know visual studio so this is a guess. But remember that c and c++ are 
very different. C++ is much more strict than c so it is possible that the ide 
is simply following the rules of c and allowing you to do dubious but legal 
things in c...

But that is just a guess.


> However, I am a lose for choosing my next editor/IDE...

I'm a vim and shell man myself but when working in c++ and java, as I 
occasionally must, I use eclipse.

But if possible I avoid ides and keep things as simple as possible, especially 
for python.

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


Re: [Tutor] Append to list

2018-05-09 Thread Steven D'Aprano
On Wed, May 09, 2018 at 10:56:45AM -0700, Rick Jaramillo wrote:
> 
> Hello,
> 
> I’m having trouble understanding the following behavior and would greatly 
> appreciate any insight. 
> 
> l = [1,2,3,4]
> b=[]
> 
> for i in range(l):

That's not actually your code, is it? Because range(l) gives a 
TypeError. In future, please copy and paste your code, don't retype it 
from memory.

> print l
> b.append(l)
> l.pop(0)

You are appending the same list each time, not a copy. Instead make a 
copy by taking a slice from the current position to the end of 
the list:

for i in range(len(l)):
b.append(l[i:])

print b


will do what you want.



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