syntax difference
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Jun 23 22:35:27 EDT 2018
On Sat, 23 Jun 2018 23:26:43 +0100, Bart wrote:
> Then [40 years ago], the easy part was reading the three numbers. Now
> that would be the more challenging part.
# Get three numbers, separated by spaces, with no error-recovery.
# If you try to read bad data, the process will fail.
n1, n2, n3 = [float(s) for s in input("Enter three numbers: ").split()]
No more verbose or difficult (certainly not "challenging") than:
var:
# need to declare these otherwise how will readln
# know if it is reading floats or ints or strings?
n1, n2, n3: float
print("Enter three numbers: ")
n1, n2, n3 = readln()
If the use of a list comprehension is too advanced for a beginner in day
one, how about this:
n1 = float(input("Enter a number: "))
n2 = float(input("Enter a number: "))
n3 = float(input("Enter a number: "))
--
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson
More information about the Python-list
mailing list