Monday 15 April 2013

How do you input integers using input in Python -



How do you input integers using input in Python -

i'm trying teach myself how code in python , first time posting stack overflow, please excuse improprieties in post. let's right it.

i'm trying utilize input command homecoming integer. i've done research, too, below multiple attempts in python 3.4 , results follow:

attempt #1 guess_row = int(input("guess row: "))

i following:

traceback (most recent phone call last): file "<input>", line 1, in <module> valueerror: invalid literal int() base of operations 10: 'guess row: 2` attempt #2 guess_row = float(input("guess row: "))

i following:

traceback (most recent phone call last): file "<input>", line 1, in <module> valueerror: not convert string float: "guess row: 2"" attempt #3 try: guess_row=int(input("guess row: ")) except valueerror: print("not integer")

here, following:

guess row: 2 not integer

although returns something, know wrong because, one, input returns string , returns print command.

point being, i've tried int, float, , try, , far nil has worked. suggestions? want able input integer , have returned one.

however, noticed odd. code works if run using traditional run (i.e., greenish button) runs entire code, rather trying execute individuals lines of code pressing f2. know why may case?

this seems problem in eclipse, the pydev faq:

why raw_input() / input() not work correctly in pydev?

the eclipse console not exact re-create of shell... 1 of changes when press in shell, may give \r, \n or \r\n end-line char, depending on platform. python not expect -- docs says remove lastly \n (checked in version 2.4), but, in platforms leave \r there. means raw_input() should used raw_input().replace('\r', ''), , input() should changed for: eval(raw_input().replace('\r', '')).

also see: pydev 3.7.1 in eclipse 4 — input() prepends prompt string input variable?, unable provide user input in pydev console on eclipse jython.

python python-3.x input int

No comments:

Post a Comment