What is use and purpose of read_text in python
up vote
-5
down vote
favorite
this is the code
import pydoc
def read_float(prompt):
while True:
try:
number_text = read_text(prompt)
result = float(number_text)
break
except ValueError:
print('Enter a number')
return result
read_float(1)
I am trying to use read_text function in python in this imageread_text program
but the in terminal i am getting a error of read_text is not defined
python python-3.x
New contributor
Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
-5
down vote
favorite
this is the code
import pydoc
def read_float(prompt):
while True:
try:
number_text = read_text(prompt)
result = float(number_text)
break
except ValueError:
print('Enter a number')
return result
read_float(1)
I am trying to use read_text function in python in this imageread_text program
but the in terminal i am getting a error of read_text is not defined
python python-3.x
New contributor
Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
read_text()isn't defined anywhere in the standard library, but you'll probably find it wherever you found the code you pasted.
– jedwards
Nov 17 at 5:37
Also please post the code instead of the image.
– Abdul Niyas P M
Nov 17 at 5:38
Thanks jedwards..i got it i have to define another function read_text in the current file..
– Ahmed Sheikh
Nov 17 at 5:45
add a comment |
up vote
-5
down vote
favorite
up vote
-5
down vote
favorite
this is the code
import pydoc
def read_float(prompt):
while True:
try:
number_text = read_text(prompt)
result = float(number_text)
break
except ValueError:
print('Enter a number')
return result
read_float(1)
I am trying to use read_text function in python in this imageread_text program
but the in terminal i am getting a error of read_text is not defined
python python-3.x
New contributor
Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
this is the code
import pydoc
def read_float(prompt):
while True:
try:
number_text = read_text(prompt)
result = float(number_text)
break
except ValueError:
print('Enter a number')
return result
read_float(1)
I am trying to use read_text function in python in this imageread_text program
but the in terminal i am getting a error of read_text is not defined
python python-3.x
python python-3.x
New contributor
Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Nov 17 at 6:31
Vaibhav Vishal
933418
933418
New contributor
Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 17 at 5:36
Ahmed Sheikh
12
12
New contributor
Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
read_text()isn't defined anywhere in the standard library, but you'll probably find it wherever you found the code you pasted.
– jedwards
Nov 17 at 5:37
Also please post the code instead of the image.
– Abdul Niyas P M
Nov 17 at 5:38
Thanks jedwards..i got it i have to define another function read_text in the current file..
– Ahmed Sheikh
Nov 17 at 5:45
add a comment |
4
read_text()isn't defined anywhere in the standard library, but you'll probably find it wherever you found the code you pasted.
– jedwards
Nov 17 at 5:37
Also please post the code instead of the image.
– Abdul Niyas P M
Nov 17 at 5:38
Thanks jedwards..i got it i have to define another function read_text in the current file..
– Ahmed Sheikh
Nov 17 at 5:45
4
4
read_text() isn't defined anywhere in the standard library, but you'll probably find it wherever you found the code you pasted.– jedwards
Nov 17 at 5:37
read_text() isn't defined anywhere in the standard library, but you'll probably find it wherever you found the code you pasted.– jedwards
Nov 17 at 5:37
Also please post the code instead of the image.
– Abdul Niyas P M
Nov 17 at 5:38
Also please post the code instead of the image.
– Abdul Niyas P M
Nov 17 at 5:38
Thanks jedwards..i got it i have to define another function read_text in the current file..
– Ahmed Sheikh
Nov 17 at 5:45
Thanks jedwards..i got it i have to define another function read_text in the current file..
– Ahmed Sheikh
Nov 17 at 5:45
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
What you're looking at is not valid python code, unless read_text() is defined somewhere out of view. The function read_text() does not exist in standard python; rather, the built-in function input() serves that purpose instead. A proper implementation of that image you've provided is:
def read_float(prompt): # prompt is a string, e.g. "Enter a float"
while True: # this is to continue trying if not-a-float is entered
try:
number_text = input(prompt) # this prompts the user for input, and returns a string
result = float(number_text) # this tries to convert the string to a float
break # exit this loop to return the float
except ValueError: # this is thrown by the previous line if number_text isn't able to be converted to a float
print('Enter a Number') # ask the user to try again
return result
The result of running this function in my python console:
>>> read_float("Enter a float, please: ")
Enter a float, please: float
Enter a Number
Enter a float, please: 7.5
7.5
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
What you're looking at is not valid python code, unless read_text() is defined somewhere out of view. The function read_text() does not exist in standard python; rather, the built-in function input() serves that purpose instead. A proper implementation of that image you've provided is:
def read_float(prompt): # prompt is a string, e.g. "Enter a float"
while True: # this is to continue trying if not-a-float is entered
try:
number_text = input(prompt) # this prompts the user for input, and returns a string
result = float(number_text) # this tries to convert the string to a float
break # exit this loop to return the float
except ValueError: # this is thrown by the previous line if number_text isn't able to be converted to a float
print('Enter a Number') # ask the user to try again
return result
The result of running this function in my python console:
>>> read_float("Enter a float, please: ")
Enter a float, please: float
Enter a Number
Enter a float, please: 7.5
7.5
add a comment |
up vote
1
down vote
accepted
What you're looking at is not valid python code, unless read_text() is defined somewhere out of view. The function read_text() does not exist in standard python; rather, the built-in function input() serves that purpose instead. A proper implementation of that image you've provided is:
def read_float(prompt): # prompt is a string, e.g. "Enter a float"
while True: # this is to continue trying if not-a-float is entered
try:
number_text = input(prompt) # this prompts the user for input, and returns a string
result = float(number_text) # this tries to convert the string to a float
break # exit this loop to return the float
except ValueError: # this is thrown by the previous line if number_text isn't able to be converted to a float
print('Enter a Number') # ask the user to try again
return result
The result of running this function in my python console:
>>> read_float("Enter a float, please: ")
Enter a float, please: float
Enter a Number
Enter a float, please: 7.5
7.5
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
What you're looking at is not valid python code, unless read_text() is defined somewhere out of view. The function read_text() does not exist in standard python; rather, the built-in function input() serves that purpose instead. A proper implementation of that image you've provided is:
def read_float(prompt): # prompt is a string, e.g. "Enter a float"
while True: # this is to continue trying if not-a-float is entered
try:
number_text = input(prompt) # this prompts the user for input, and returns a string
result = float(number_text) # this tries to convert the string to a float
break # exit this loop to return the float
except ValueError: # this is thrown by the previous line if number_text isn't able to be converted to a float
print('Enter a Number') # ask the user to try again
return result
The result of running this function in my python console:
>>> read_float("Enter a float, please: ")
Enter a float, please: float
Enter a Number
Enter a float, please: 7.5
7.5
What you're looking at is not valid python code, unless read_text() is defined somewhere out of view. The function read_text() does not exist in standard python; rather, the built-in function input() serves that purpose instead. A proper implementation of that image you've provided is:
def read_float(prompt): # prompt is a string, e.g. "Enter a float"
while True: # this is to continue trying if not-a-float is entered
try:
number_text = input(prompt) # this prompts the user for input, and returns a string
result = float(number_text) # this tries to convert the string to a float
break # exit this loop to return the float
except ValueError: # this is thrown by the previous line if number_text isn't able to be converted to a float
print('Enter a Number') # ask the user to try again
return result
The result of running this function in my python console:
>>> read_float("Enter a float, please: ")
Enter a float, please: float
Enter a Number
Enter a float, please: 7.5
7.5
answered Nov 17 at 6:00
Green Cloak Guy
2,178720
2,178720
add a comment |
add a comment |
Ahmed Sheikh is a new contributor. Be nice, and check out our Code of Conduct.
Ahmed Sheikh is a new contributor. Be nice, and check out our Code of Conduct.
Ahmed Sheikh is a new contributor. Be nice, and check out our Code of Conduct.
Ahmed Sheikh is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348557%2fwhat-is-use-and-purpose-of-read-text-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
read_text()isn't defined anywhere in the standard library, but you'll probably find it wherever you found the code you pasted.– jedwards
Nov 17 at 5:37
Also please post the code instead of the image.
– Abdul Niyas P M
Nov 17 at 5:38
Thanks jedwards..i got it i have to define another function read_text in the current file..
– Ahmed Sheikh
Nov 17 at 5:45