Is there a way to access what is never assigned?

while int(input("choose a number")) != 5 : 

Let's say I wanted to see which number was entered. Is there an indirect way to get from this?

EDIT Im probably not very clear., I know that in the debugger you can view and find out what number is being entered. Maybe a memory hack or something like that that allows you to get the "old" data after the fact?

+4
source share
4 answers

No - you need to assign it ... Your example can be written using the iter two argument style, though:

 for number in iter(lambda: int(input('Choose a number: ')), 5): print number # prints it if it wasn't 5... 
+7
source

Do something like that. You do not need to assign, but simply compose an additional function and use it every time you need to do this. Hope this helps.

 def printAndReturn(x): print(x); return(x) while printAndReturn(int(input("choose a number"))) != 5 : # do your stuff 
+2
source

No, there is no access to this input as you did, you would have to store it. Here is an example of a hello world level

 val = int(input("choose a number")) while val != 5 : val = int(input("choose a number")) 
+1
source

A semi-related hacker solution that technically answers your question, but not real:

If you run this in a python interactive environment (thing with >>> ) you can do it

 >>>while int(input("choose a number: ")) != 5 : ... print _ ... choose a number: 2 2 choose a number: 5 >>> 

Please note that this only works in an interactive environment.

+1
source

Source: https://habr.com/ru/post/1492353/


All Articles