Question again

2021-09-16 Thread af kh
Hello,
I was doing some coding on a website called replit then I extracted the file, 
and opened it in Python. For some reason, after answering 'no' or 'yes' after 
the last sentence I wrote, the Python window shut off, in replit I added one 
more sentence, but it isn't shown on Python, it just shuts off. Why is that? 
please reply to me soon since I need to submit it as an assignment for my class.

Code on replit:
#Title: Week 2: Chatbot with personality
#Author: Afnan Khan
#Date:9/15/21
#Description: Ask at least 3 questions to the user
#and create a creative topic

#Gives greetings to the user
import random

greetings = ["Hello, I'm Mr. ChatBot!", "Hi, I'm Mr. ChatBot!", "Hey~, I'm Mr. 
ChatBot!"]
comment = random.choice(greetings)
print(comment)
#Learn about the user's Name: First question
name = input("What is your name? ")

#Greet the User
print("Nice to meet you, " + name)

#Ask the user about their day: Second question
print("How is your day going? ")

#The user replies
reply = input()

#If user says 'amazing', reply with 'I am glad!'
if reply == "amazing" :
  print("I am glad!")

#If user says 'Alright', reply with 'that's good'
elif reply == "alright" :
  print("that's good")

#If user says 'bad', reply with 'Do not worry things will get better'
elif reply == "bad" :
  print("Do not worry things will get better")

#Else than that type 'I see'
else :
  print("I see!")

#Ask to pick between numbers 1~10 to see if you will get lucky today: Third 
question
number = input("Please pick between numbers 1~10 to see your luck for today: ")

#From number 1~3 and an answer
if number == "1" or number == "2" or number == "3" :
  print("You're in grat luck today!")

#From number 4~7 and an answer
elif number == "4" or number == "5" or number == "6" :
  print("damn, bad luck is coming your way")

#From number 8~10 and an answer
elif number == "7" or number == "8" or number == "9" or number == "10" :
  print("I cannot sense any luck today, try again next time")

#Add a statement and question: Fourth question
print("That will be all for today's chitchat, woohooo! would you like to exit 
the chat?")

#User says 'yes'
reply = input()

#If user says 'yes' reply 'wait hold on! are you really leaving??': Fifth 
question
if reply == "yes" :
  print("Wait hold on! are you really leaving??")

#User answers
answer = input()

#If user says 'yes' again, reply 'fine! bye then!'
if answer == "yes" :
  print("Fine! bye then!")

#Other than that if user says 'no', reply 'just kidding we're done here haha'
elif answer == "no" :
  print("just kidding we're done here haha")


Regards,
Aya
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-16 Thread Mostowski Collapse
Compound is not used for boxing. Integers and floats
are represented directly. Also integers are not mapped to
floats. But maybe compound could be a little flattened,

like using directly an array. But then you cannot assure
anymore "clean, simple, readable code". For example now
I have clean, simple and readable code, since I can

access the functor of a compound via:

 obj.functor

but when I flatten Compound into arrays, it would become:

 obj[0]

Should I declare a constant FUNCTOR = 0? Some of your 
requirements have a trade-off, not all of them can be
sustained simultaneously so easy.

I am rather expecting languages like Python and JavaScript
to offer the same comfort as C or Java, except that
I don't need to write types for all the varianbles and fields

all the time. But this requires smart language compiler
and language runtime. V8 Chrome has interesting articles
how they optimize access like .functor.

Chris Angelico schrieb am Donnerstag, 16. September 2021 um 00:02:54 UTC+2:
> On Thu, Sep 16, 2021 at 7:59 AM Mostowski Collapse  wrote: 
> > 
> > BTW: I could already make it faster, by not repeatedly 
> > accessing .arg anymore. It went down from ca.: 
> > 
> > 171'000 ms 
> > 
> > To this here: 
> > 
> > 140'000 ms 
> > 
> > But only in the cold run. In the warm run it went back 
> > to 171'000 ms. Possibly when my code is faster, 
> > it will create objects more faster, and kill the Python GC. 
> > 
> > Or it was because my Laptop went into screen black? 
> > And throttled the CPU. Not sure. 
> >
> Instead of worrying about all these details, start by simplifying your 
> code. Focus on clean, simple, readable code, and don't microoptimize. 
> Specifically, focus on the core arithmetic that you're trying to do, 
> and get rid of all the bookkeeping overhead; most of that is a waste 
> of time. I mentioned earlier the repeated boxing and unboxing in 
> "Compound" objects - have you changed anything with those? 
> 
> ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-16 Thread Chris Angelico
On Fri, Sep 17, 2021 at 3:20 AM Mostowski Collapse  wrote:
>
> Compound is not used for boxing. Integers and floats
> are represented directly. Also integers are not mapped to
> floats. But maybe compound could be a little flattened,
>

"Boxing" in this case isn't about ints and floats, since Java-like
bizarrenesses simply don't happen in Python; I'm talking about the way
that you frequently build up a Compound object for various situations
(even for throwing an error - you have a function that constructs a
generic Exception, and then buries a Compound inside it), and then
you're frequently checking if something is an instance of Compound.
All these constant back-and-forths are extremely expensive, since
they're not part of your algorithm at all.

At very least, use tuples instead of Compounds, but it would be far
better to ask less questions about your data and do more things by
tidying up your algorithm. Unfortunately, I can't really advise with
any detail, because you have code like this:

###
# Mark a term.
#
# @param term The term.
##
def mark_term(term):

What does that even mean?! I get it, you have a term, and you're
marking it. Whatever that mark means. The comments add absolutely
nothing that the function header didn't tell me. Are you implementing
your own garbage collection on top of Python's? Or something else?
It's extremely hard to give any sort of recommendations when your code
is hard to read, and nearly all of the comments are nothing more than
restating what can be seen in the next line of code. Also, with the
number of globals you're using, tracing the purpose of your functions
is not easy.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question again

2021-09-16 Thread DFS

On 9/16/2021 1:50 AM, af kh wrote:

Hello,
I was doing some coding on a website called replit then I extracted the file, 
and opened it in Python. For some reason, after answering 'no' or 'yes' after 
the last sentence I wrote, the Python window shut off, in replit I added one 
more sentence, but it isn't shown on Python, it just shuts off. Why is that? 
please reply to me soon since I need to submit it as an assignment for my class.

Code on replit:
#Title: Week 2: Chatbot with personality
#Author: Afnan Khan
#Date:9/15/21
#Description: Ask at least 3 questions to the user
#and create a creative topic

#Gives greetings to the user
import random

greetings = ["Hello, I'm Mr. ChatBot!", "Hi, I'm Mr. ChatBot!", "Hey~, I'm Mr. 
ChatBot!"]
comment = random.choice(greetings)
print(comment)
#Learn about the user's Name: First question
name = input("What is your name? ")

#Greet the User
print("Nice to meet you, " + name)

#Ask the user about their day: Second question
print("How is your day going? ")

#The user replies
reply = input()

#If user says 'amazing', reply with 'I am glad!'
if reply == "amazing" :
   print("I am glad!")

#If user says 'Alright', reply with 'that's good'
elif reply == "alright" :
   print("that's good")

#If user says 'bad', reply with 'Do not worry things will get better'
elif reply == "bad" :
   print("Do not worry things will get better")

#Else than that type 'I see'
else :
   print("I see!")

#Ask to pick between numbers 1~10 to see if you will get lucky today: Third 
question
number = input("Please pick between numbers 1~10 to see your luck for today: ")

#From number 1~3 and an answer
if number == "1" or number == "2" or number == "3" :
   print("You're in grat luck today!")

#From number 4~7 and an answer
elif number == "4" or number == "5" or number == "6" :
   print("damn, bad luck is coming your way")

#From number 8~10 and an answer
elif number == "7" or number == "8" or number == "9" or number == "10" :
   print("I cannot sense any luck today, try again next time")

#Add a statement and question: Fourth question
print("That will be all for today's chitchat, woohooo! would you like to exit the 
chat?")

#User says 'yes'
reply = input()

#If user says 'yes' reply 'wait hold on! are you really leaving??': Fifth 
question
if reply == "yes" :
   print("Wait hold on! are you really leaving??")

#User answers
answer = input()

#If user says 'yes' again, reply 'fine! bye then!'
if answer == "yes" :
   print("Fine! bye then!")

#Other than that if user says 'no', reply 'just kidding we're done here haha'
elif answer == "no" :
   print("just kidding we're done here haha")


Regards,
Aya



I don't understand your issue, but this code runs fine for me.

--
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-16 Thread Mostowski Collapse

About Exceptions: Thats just building ISO core
standard Prolog error terms.

About Garbage Collection: Thats just Prolog
garbage collection, which does shrink some
single linked lists, which ordinary
programmig language GC cannot do,

or maybe some Weak Pointer magic can do it?
The use case is very simple. A Prolog system
has a so called trail. The trail in Dogelog
Runtime is a single linked list:

-->[ A ]-->[ B ]-->[ C ]-->

Now if B becomes unused, you need to rewire
the trail, it should then look like:

-->[ A ]-->[ C ]-->


If a programming language has a means to
communicate this to the Garbage Collector,
I happy to apply it. The challenge is many
fold, the pointer from A to B for example

needs not to be accounted to determine
whether B is reachable. So all the links
in the trail are weak pointers. But they
are weak pointers that need to

be able to adapt.

Chris Angelico wrote:

On Fri, Sep 17, 2021 at 3:20 AM Mostowski Collapse  wrote:


Compound is not used for boxing. Integers and floats
are represented directly. Also integers are not mapped to
floats. But maybe compound could be a little flattened,



"Boxing" in this case isn't about ints and floats, since Java-like
bizarrenesses simply don't happen in Python; I'm talking about the way
that you frequently build up a Compound object for various situations
(even for throwing an error - you have a function that constructs a
generic Exception, and then buries a Compound inside it), and then
you're frequently checking if something is an instance of Compound.
All these constant back-and-forths are extremely expensive, since
they're not part of your algorithm at all.

At very least, use tuples instead of Compounds, but it would be far
better to ask less questions about your data and do more things by
tidying up your algorithm. Unfortunately, I can't really advise with
any detail, because you have code like this:

###
# Mark a term.
#
# @param term The term.
##
def mark_term(term):

What does that even mean?! I get it, you have a term, and you're
marking it. Whatever that mark means. The comments add absolutely
nothing that the function header didn't tell me. Are you implementing
your own garbage collection on top of Python's? Or something else?
It's extremely hard to give any sort of recommendations when your code
is hard to read, and nearly all of the comments are nothing more than
restating what can be seen in the next line of code. Also, with the
number of globals you're using, tracing the purpose of your functions
is not easy.

ChrisA



--
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-16 Thread Mostowski Collapse

Here is a challenge for Python.
Can Python solve Sudoku?

Mostowski Collapse wrote:

I am not testing this use-case. But a related
use-case might highlight why speed did never
hurt anybody.

Lets say you program a flying drone with Python,
and the measurement is from the drone sensor
and communication systems.

Lets say you are using the idle time between
measurements for some complex planning. It
is then not true that you have anyway

to wait for the measurement.

Hope this helps!

BTW: If somebody knows another Python implementation
I am happy to test this implementation as well.
I am assuming that the standard Python python.exe

I tested amounts to CPython? Not sure. And the
GraalVM is practically the same as JPython? Not
sure either.

Opinion:   Anyone who is counting on Python for truly fast compute 
speed is probably using Python for the wrong purpose. Here, we use 
Python to control Test Equipment, to set up the equipment and ask for 
a measurement, get it, and proceed to the next measurement; and at the 
end produce a nice formatted report. If we wrote the test script in C 
or Rust or whatever it could not run substantially faster because it 
is communicating with the test equipment, setting it up and waiting 
for responses, and that is where the vast majority of the time goes. 
Especially if the measurement result requires averaging it can take a 
while.  In my opinion this is an ideal use for Python, not just 
because the speed of Python is not important, but also because we can 
easily find people who know Python, who like coding in Python, and 
will join the company to program in Python ... and stay with us.

--- Joseph S.




--
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-16 Thread Mostowski Collapse
A friend just sent me a Web Sudoku made with Dogelog Runtime
https://gist.github.com/jburse/c85297e97091caf22d306dd8c8be12fe#gistcomment-3895696

LoL

Mostowski Collapse schrieb am Donnerstag, 16. September 2021 um 21:59:05 UTC+2:
> Here is a challenge for Python. 
> Can Python solve Sudoku? 
> 
> Mostowski Collapse wrote: 
> > I am not testing this use-case. But a related 
> > use-case might highlight why speed did never 
> > hurt anybody. 
> > 
> > Lets say you program a flying drone with Python, 
> > and the measurement is from the drone sensor 
> > and communication systems. 
> > 
> > Lets say you are using the idle time between 
> > measurements for some complex planning. It 
> > is then not true that you have anyway 
> > 
> > to wait for the measurement. 
> > 
> > Hope this helps! 
> > 
> > BTW: If somebody knows another Python implementation 
> > I am happy to test this implementation as well. 
> > I am assuming that the standard Python python.exe 
> > 
> > I tested amounts to CPython? Not sure. And the 
> > GraalVM is practically the same as JPython? Not 
> > sure either. 
> > 
> >> Opinion: Anyone who is counting on Python for truly fast compute 
> >> speed is probably using Python for the wrong purpose. Here, we use 
> >> Python to control Test Equipment, to set up the equipment and ask for 
> >> a measurement, get it, and proceed to the next measurement; and at the 
> >> end produce a nice formatted report. If we wrote the test script in C 
> >> or Rust or whatever it could not run substantially faster because it 
> >> is communicating with the test equipment, setting it up and waiting 
> >> for responses, and that is where the vast majority of the time goes. 
> >> Especially if the measurement result requires averaging it can take a 
> >> while. In my opinion this is an ideal use for Python, not just 
> >> because the speed of Python is not important, but also because we can 
> >> easily find people who know Python, who like coding in Python, and 
> >> will join the company to program in Python ... and stay with us. 
> >> --- Joseph S. 
> >
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-16 Thread Avi Gross via Python-list
Some questions make no sense to me.

Can a kind of snake solve Sudoku? Do you mean a specific puzzle, or any puzzle 
or even a puzzle with no solution?

Can a programming language do it? Well, in my experience, programming languages 
are tools to be used by humans, or sometimes by other programming languages. 
They are not sentient and cannot be asked to solve much of anything.

So is the question whether someone can program using only Python to solve an 
arbitrary sudoku problem? Short answer is you can do that in just about ANY 
language. I mean by brute force, if you have a 9 by 9 matrix with some of the 
81 locations already filled in, then you can try every darn combination of the 
other spots using digits 1 to 9 and then ignore any where the rows and columns 
and the 9 3x3 submatrices do not follow the rules. At least one solution is 
guaranteed to pop out if there is one. Sure, such methods may run out of memory 
or take a while, but many can use little memory and some can speed things up by 
not going down blind alleys such as placing a number in a position where there 
already is the same number on the same row or column or sub-matrix.

So is the real question whether a human has already made a decent 
implementation in Python available? Sure, do a little searching and there are 
plenty of such things including some that use interesting features of python 
and some that are just translations from a more primitive language.



-Original Message-
From: Python-list  On 
Behalf Of Mostowski Collapse
Sent: Thursday, September 16, 2021 3:59 PM
To: [email protected]
Subject: Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

Here is a challenge for Python.
Can Python solve Sudoku?

Mostowski Collapse wrote:
> I am not testing this use-case. But a related use-case might highlight 
> why speed did never hurt anybody.
> 
> Lets say you program a flying drone with Python, and the measurement 
> is from the drone sensor and communication systems.
> 
> Lets say you are using the idle time between measurements for some 
> complex planning. It is then not true that you have anyway
> 
> to wait for the measurement.
> 
> Hope this helps!
> 
> BTW: If somebody knows another Python implementation I am happy to 
> test this implementation as well.
> I am assuming that the standard Python python.exe
> 
> I tested amounts to CPython? Not sure. And the GraalVM is practically 
> the same as JPython? Not sure either.
> 
>> Opinion:   Anyone who is counting on Python for truly fast compute 
>> speed is probably using Python for the wrong purpose. Here, we use 
>> Python to control Test Equipment, to set up the equipment and ask for 
>> a measurement, get it, and proceed to the next measurement; and at 
>> the end produce a nice formatted report. If we wrote the test script 
>> in C or Rust or whatever it could not run substantially faster 
>> because it is communicating with the test equipment, setting it up 
>> and waiting for responses, and that is where the vast majority of the time 
>> goes.
>> Especially if the measurement result requires averaging it can take a 
>> while.  In my opinion this is an ideal use for Python, not just 
>> because the speed of Python is not important, but also because we can 
>> easily find people who know Python, who like coding in Python, and 
>> will join the company to program in Python ... and stay with us.
>> --- Joseph S.
> 

-- 
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-16 Thread Mostowski Collapse
The new release 0.9.6 is quite speedy:

"Maailman vaikein" 
85000240072009004010700230500090004000800700170036040
 
time(solve(Puzzle)) 
% Wall 41354 ms, gc 520 ms, 3143029 lips 
in Browser

See also:

Preview: New para/1 instruction for Dogelog runtime. (Jekejeke)
https://twitter.com/dogelogch/status/1438586282502983682

Preview: New para/1 instruction for Dogelog runtime. (Jekejeke)
https://www.facebook.com/groups/dogelog

Avi Gross schrieb am Donnerstag, 16. September 2021 um 23:43:10 UTC+2:
> Some questions make no sense to me. 
> 
> Can a kind of snake solve Sudoku? Do you mean a specific puzzle, or any 
> puzzle or even a puzzle with no solution? 
> 
> Can a programming language do it? Well, in my experience, programming 
> languages are tools to be used by humans, or sometimes by other programming 
> languages. They are not sentient and cannot be asked to solve much of 
> anything. 
> 
> So is the question whether someone can program using only Python to solve an 
> arbitrary sudoku problem? Short answer is you can do that in just about ANY 
> language. I mean by brute force, if you have a 9 by 9 matrix with some of the 
> 81 locations already filled in, then you can try every darn combination of 
> the other spots using digits 1 to 9 and then ignore any where the rows and 
> columns and the 9 3x3 submatrices do not follow the rules. At least one 
> solution is guaranteed to pop out if there is one. Sure, such methods may run 
> out of memory or take a while, but many can use little memory and some can 
> speed things up by not going down blind alleys such as placing a number in a 
> position where there already is the same number on the same row or column or 
> sub-matrix. 
> 
> So is the real question whether a human has already made a decent 
> implementation in Python available? Sure, do a little searching and there are 
> plenty of such things including some that use interesting features of python 
> and some that are just translations from a more primitive language.
> -Original Message- 
> From: Python-list  On 
> Behalf Of Mostowski Collapse 
> Sent: Thursday, September 16, 2021 3:59 PM 
> To: [email protected] 
> Subject: Re: ANN: Dogelog Runtime, Prolog to the Moon (2021) 
> 
> Here is a challenge for Python. 
> Can Python solve Sudoku? 
> 
> Mostowski Collapse wrote: 
> > I am not testing this use-case. But a related use-case might highlight 
> > why speed did never hurt anybody. 
> > 
> > Lets say you program a flying drone with Python, and the measurement 
> > is from the drone sensor and communication systems. 
> > 
> > Lets say you are using the idle time between measurements for some 
> > complex planning. It is then not true that you have anyway 
> > 
> > to wait for the measurement. 
> > 
> > Hope this helps! 
> > 
> > BTW: If somebody knows another Python implementation I am happy to 
> > test this implementation as well. 
> > I am assuming that the standard Python python.exe 
> > 
> > I tested amounts to CPython? Not sure. And the GraalVM is practically 
> > the same as JPython? Not sure either. 
> > 
> >> Opinion: Anyone who is counting on Python for truly fast compute 
> >> speed is probably using Python for the wrong purpose. Here, we use 
> >> Python to control Test Equipment, to set up the equipment and ask for 
> >> a measurement, get it, and proceed to the next measurement; and at 
> >> the end produce a nice formatted report. If we wrote the test script 
> >> in C or Rust or whatever it could not run substantially faster 
> >> because it is communicating with the test equipment, setting it up 
> >> and waiting for responses, and that is where the vast majority of the time 
> >> goes. 
> >> Especially if the measurement result requires averaging it can take a 
> >> while. In my opinion this is an ideal use for Python, not just 
> >> because the speed of Python is not important, but also because we can 
> >> easily find people who know Python, who like coding in Python, and 
> >> will join the company to program in Python ... and stay with us. 
> >> --- Joseph S. 
> >
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question again

2021-09-16 Thread Alan Gauld via Python-list
On 16/09/2021 06:50, af kh wrote:
> Hello,
> I was doing some coding on a website called replit 

I have no idea what that is but...

> after answering 'no' or 'yes' after the last sentence I wrote, 
> the Python window shut off,

That's what you told it to do in the code.
Regardless of which answer the user gives the program
reaches the end and stops.

>  in replit I added one more sentence, but it isn't shown on Python, 

I dn;t know what this means.

> #Gives greetings to the user
> import random
...
> #Ask to pick between numbers 1~10 to see if you will get lucky today: Third 
> question
> number = input("Please pick between numbers 1~10 to see your luck for today: 
> ")
> 
> #From number 1~3 and an answer
> if number == "1" or number == "2" or number == "3" :
>   print("You're in grat luck today!")
> 
> #From number 4~7 and an answer
> elif number == "4" or number == "5" or number == "6" :
>   print("damn, bad luck is coming your way")

The cde and comment are not consistent.

> #From number 8~10 and an answer
> elif number == "7" or number == "8" or number == "9" or number == "10" :
>   print("I cannot sense any luck today, try again next time")

Same here.

> #Add a statement and question: Fourth question
> print("That will be all for today's chitchat, woohooo! would you like to exit 
> the chat?")
> #User says 'yes'
> reply = input()
> 
> #If user says 'yes' reply 'wait hold on! are you really leaving??': Fifth 
> question
> if reply == "yes" :
>   print("Wait hold on! are you really leaving??")
> 
> #User answers
> answer = input()
> #If user says 'yes' again, reply 'fine! bye then!'
> if answer == "yes" :
>   print("Fine! bye then!")


Shouldn't those lines be indented as part of the if statement above?

> #Other than that if user says 'no', reply 'just kidding we're done here haha'
> elif answer == "no" :
>   print("just kidding we're done here haha")

But the code always gets to the end, there is nothing
to stop it exiting.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Question again

2021-09-16 Thread Avi Gross via Python-list
Alan,

I wonder if this is yet another case when a pop-up window closes rapidly
when done and any last text written is just not perceived.

Good design in such cases makes a final pause till the user acknowledges in
some way that they are done and then no more messages!

Avi

-Original Message-
From: Python-list  On
Behalf Of Alan Gauld via Python-list
Sent: Thursday, September 16, 2021 8:11 PM
To: [email protected]
Subject: Re: Question again

On 16/09/2021 06:50, af kh wrote:
> Hello,
> I was doing some coding on a website called replit

I have no idea what that is but...

> after answering 'no' or 'yes' after the last sentence I wrote, the 
> Python window shut off,

That's what you told it to do in the code.
Regardless of which answer the user gives the program reaches the end and
stops.

>  in replit I added one more sentence, but it isn't shown on Python,

I dn;t know what this means.

> #Gives greetings to the user
> import random
...
> #Ask to pick between numbers 1~10 to see if you will get lucky today: 
> Third question number = input("Please pick between numbers 1~10 to see 
> your luck for today: ")
> 
> #From number 1~3 and an answer
> if number == "1" or number == "2" or number == "3" :
>   print("You're in grat luck today!")
> 
> #From number 4~7 and an answer
> elif number == "4" or number == "5" or number == "6" :
>   print("damn, bad luck is coming your way")

The cde and comment are not consistent.

> #From number 8~10 and an answer
> elif number == "7" or number == "8" or number == "9" or number == "10" :
>   print("I cannot sense any luck today, try again next time")

Same here.

> #Add a statement and question: Fourth question print("That will be all 
> for today's chitchat, woohooo! would you like to exit the chat?") 
> #User says 'yes'
> reply = input()
> 
> #If user says 'yes' reply 'wait hold on! are you really leaving??': 
> Fifth question if reply == "yes" :
>   print("Wait hold on! are you really leaving??")
> 
> #User answers
> answer = input()
> #If user says 'yes' again, reply 'fine! bye then!'
> if answer == "yes" :
>   print("Fine! bye then!")


Shouldn't those lines be indented as part of the if statement above?

> #Other than that if user says 'no', reply 'just kidding we're done here
haha'
> elif answer == "no" :
>   print("just kidding we're done here haha")

But the code always gets to the end, there is nothing to stop it exiting.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The code version of python -i

2021-09-16 Thread dn via Python-list
Abdur-Rahmaan,
Apologies for delay: several last-minute tasks were landed on me, so I
haven't been able to 'read the list' since last week.


> If i have a file name flower.py and i add x = 1 in it.
> When i run python -i flower.py i get a shell

> 
> If type x i get 1
 x
> 1
> 
> The values are auto injected.
> 
> How do i start a shell by code with values already injected? Thanks


What do you want to achieve with this?


At this week's local PUG meeting, I was 'the warm-up act' for (our own)
@Chris Angelico giving a talk about 'the walrus operator', his part in
that PEP, and how anyone-and-everyone can contribute to the Python
eco-system.

My contribution was to start at the Python-Apprentice level, talking
about different types of 'operators', and preparing the stage?beach for
the more advanced 'walrus'. It culminated in a live-coding demo of
Conditional expressions/the "ternary operator".

Live-coding demos are always better (for the audience) than passively
watching a progression of slides! However, that territory is labelled
'here be dragons', for presenters! (continuing the tradition of slide
projectors which don't accept my cartridge/carousel, white boards
lacking pens with ink, over-head projectors with blown lamps (and a used
spare), RGB projectors which only/don't accept VGA cables, ...)

Further: we've all suffered YouTube wannabes telling us how easy it is
to do 'something', typing and mis-typing and re-typing, and generally
wasting our time... (have they not heard of video-editing?) Those of us
who present 'live' (unlike my video-lectures), can't rely upon a later
'cosmetic' stage to apply lip-stick on any 'pigs' in our typing!

Rather than using a "script" document (as-in 'speaker's notes') to
prompt me with what to type next, the remote presentation tool
(BigBlueButton web-conferencing) allows the 'projection' of a (desktop)
terminal window - whilst hiding my text-editor. Thus, at the appropriate
moment, I was copy-pasting from my 'script' in xed, into the terminal's
Python REPL. Worked very well - it appears as if I'm a very fast typist!
Of course, sometimes I was copying one line of code at a time, and at
others, multiple lines - thus (*still*) giving opportunity to 'fluff my
lines'. Hah!

For live-demos, I like to use pedagogical (teaching) 'patterns' of a
structured narrative (as one would with a lecture) but trying to
encourage involvement (if not "active learning"), using a "worked
example" (learning through demonstration), and "discovery" (which
because it is effectively a 'presentation', really means 'gradual
revelation').

(apologies for any non-obvious, non-Python, jargon - cognitive
psychology (learning how we learn) is my research field)

Thus, the demo proceeds on a step-by-step basis. At each step the
process is:
1 present a problem/ask a question
2 ensure understanding/invite comments/accept suggestions
3 present code snippet*
and (presumably) execute same to produce an 'answer'
4 comment/discuss/critique

- which, unless 'the end', should lead us back to nr1 for the 'next step'...

* in other scenarios, this might involve use of code suggested by the
audience!

Before reading this thread, I had been thinking that Jupyter might
empower the combination of Python, 'steps', and 'live-coding'. However,
a notebook will likely display future steps on-screen, before the
current one has been completed (which defeats 'gradual revelation' -
somewhat like jumping to 'the last page to find-out who dunnit') -
unlike (say) presentation slides where no-one can see 'what comes
next'/jump ahead, before the earlier 'lesson' has been learned.

NB I'm not seeking 'information hiding' or encapsulation by its Java
definition; but do want people to consider (only) one sub-problem at a
time, and thus building-up to the whole solution! If one first
understands the problem(s) and then contributes to generating a
solution, you will learn far more effectively than if I simply
lecture/read the Python manual-entry to you!

Courtesy of this discussion, am wondering if it might be possible to
structure what is currently a 'teaching notes' or "script" document
(from which I was copy-pasting), and build a 'projector' program which
will run a sub-interpreter* to run exactly one 'step' of the
'live-coding' demo at a time (whilst also retaining the option of REPL
access, to be able prove or expose short-comings (nr 4, above), and
without revealing the 'what comes next'?

* rather than python -i; am considering Lib.runpy, and/or Lib.code


How might any of this relate to your interest?
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-16 Thread Chris Angelico
On Fri, Sep 17, 2021 at 7:17 AM Mostowski Collapse  wrote:
>
> About Exceptions: Thats just building ISO core
> standard Prolog error terms.
>
> About Garbage Collection: Thats just Prolog
> garbage collection, which does shrink some
> single linked lists, which ordinary
> programmig language GC cannot do,
>

Okay, so you're building your own garbage collection on top of
Python's, and you're wondering why it's slow?

Change your code to not try to implement one language inside another,
and you'll see a massive performance improvement.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-16 Thread Greg Ewing

On 16/09/21 4:23 am, Mostowski Collapse wrote:

I really wonder why my Python implementation
is a factor 40 slower than my JavaScript implementation.


There are Javascript implementations around nowadays that are
blazingly fast. Partly that's because a lot of effort has been
put into them, but it's also because Javascript is a different
language. There are many dynamic aspects to Python that make
fast implementations difficult.


I use in Python:

   temp = [NotImplemented] * code[pos]
   pos += 1

is the the idiom [_] * _ slow?


No, on the contrary it's probably the fastest way to do it
in Python. You could improve it a bit by precomputing
[NotImplemented]:

# once at the module level
NotImplementedList = [NotImplemented]

# whenever you want a new list
temp = NotImplementedList * code[pos]

That's probably at least as fast as built-in function for
creating lists would be.


does it really first create an
array of size 1 and then enlarge it?


It does:

>>> def f(code, pos):
...  return [NotImplemented] * code[pos]
...
>>> from dis import dis
>>> dis(f)
  2   0 LOAD_GLOBAL  0 (NotImplemented)
  2 BUILD_LIST   1
  4 LOAD_FAST0 (code)
  6 LOAD_FAST1 (pos)
  8 BINARY_SUBSCR
 10 BINARY_MULTIPLY
 12 RETURN_VALUE

BTW, the Python terminology is "list", not "array".
(There *is* something in the stdlib called an array, but
it's rarely used or needed.)

--
Greg

--
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-16 Thread Greg Ewing

On 16/09/21 2:56 pm, Mostowski Collapse wrote:

I can access the functor of a compound via:

  obj.functor

but when I flatten Compound into arrays, it would become:

  obj[0]

Should I declare a constant FUNCTOR = 0?


You could, but keep in mind that access to a global in Python
is somewhat expensive, since it requires a dictionary lookup.

There's always a tradeoff between clarity and efficiency.
In this case, I think obj[0] is clear enough -- the reader
will be well aware that the first item of a term is the
functor. Especially if you use a name that makes it clear
what kind of object it is, rather than a generic name such
as "obj".

--
Greg

--
https://mail.python.org/mailman/listinfo/python-list


Re: Question again

2021-09-16 Thread dn via Python-list
On 17/09/2021 12.25, Avi Gross via Python-list wrote:
> I wonder if this is yet another case when a pop-up window closes rapidly
> when done and any last text written is just not perceived.
> 
> Good design in such cases makes a final pause till the user acknowledges in
> some way that they are done and then no more messages!
> -Original Message-
> From: Python-list  On
> Behalf Of Alan Gauld via Python-list
> Sent: Thursday, September 16, 2021 8:11 PM
> To: [email protected]
> Subject: Re: Question again
> 
> On 16/09/2021 06:50, af kh wrote:
>> after answering 'no' or 'yes' after the last sentence I wrote, the 

Are you using MS-Windows?
Are you executing the program directly/from the menu?
(or do you first start a terminal window, and then run Python within that)

-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list