integer_number = int(input("something here"))
is just an abbreviated way of saying:
temp_var = input("something here")
integer_number = int(temp_var)
It is not the other way around, because the int() function takes a string and converts it into an int. If you did it the other way around, the function wouldn't have anything to convert.
integer_number = int(input("something here"))
is just an abbreviated way of saying:
temp_var = input("something here")
integer_number = int(temp_var)
It is not the other way around, because the int() function takes a string and converts it into an int. If you did it the other way around, the function wouldn't have anything to convert.
In Python you can pass functions as arguments of another function and of course they'll be evaluated before the outer function. Guess I should point you to the relevant official Python documentation that states that, but just googling for it isn't working right now.
See Python’s Functions Are First-Class:
Python's functions are first-class objects. You can assign them to variables, store them in data structures, pass them as arguments to other functions, and even return them as values from other functions.
Got a nice answer about that on SO :
What are "first-class" objects:
In short, it means there are no restrictions on the object's use. It's the same as any other object.
A first class object is an entity that can be dynamically created, destroyed, passed to a function, returned as a value, and have all the rights as other variables in the programming language have.
Your one is not the first question about that:
All arguments are evaluated before the function is called:
Answer:
You are right, all arguments are evaluated before the function is called, otherwise the function cannot know what is passed to it. So what you are doing is actually:
but no link to docs here too.
Took a while, I found it here:
6.3.4. Calls its the link for Python 3:
...............All argument expressions are evaluated before the call is attempted. Please refer to section Function definitions for the syntax of formal parameter lists.........
I have to make a script that takes grades in a while loop and when the user is done entering grades they enter 'done'. I got the loop to continuously run but when I enter 'done' it says: "invalid literal for int() with base 10: 'done'"
Your third attempt is correct - but what is happening to guess_row before/after this code? For example, consider the following:
a = "Hello"
try:
a = int(input("Enter a number: "))
except ValueError:
print("Not an integer value...")
print(str(a))
If you enter a valid number, the final line will print out the value you entered. If not, an exception will be raised (showing the error message in the except block) and a will remain unchanged, so the final line will print "Hello" instead.
You can refine this so that an invalid number will prompt the user to re-enter the value:
a = None
while a is None:
try:
a = int(input("Enter a number: "))
except ValueError:
print("Not an integer value...")
print(str(a))
To illustrate the comments, from 3.4.2 Idle Shell on Windows, python.org (PSF) installer
>>> n = int(input('Guess1: '))
Guess1: 2
>>> n2 = float(input('Guess2: '))
Guess2: 3.1
>>> n, n2
(2, 3.1)
What system are you using and how did you install Python?