I am working on an assignment in college using RUR-PLE as a starting program. I don't know if you know what that is or not, but I was wondering how to use it? I enter in this code:

``````x = input("How many beepers are in this maze?")
def place_all():
repeat(put_beeper,totalBeepers)
def final_move():
if front_is_clear():
place_all()
move()
elif left_is_clear():
turn_left()
place_all()
move()
elif right_is_clear():
turn_right()
place_all()
move()
else: turn_around()
place_all()
move()
def turn_right():
repeat(turn_left,3)
def turn_around():
repeat(turn_left,2)
def move_around():
numberOfBeepers = 0
if left_is_clear():
turn_left()
move()
elif front_is_clear():
move()
elif right_is_clear():
turn_right()
move()
else:
turn_around()
while on_beeper():
pick_beeper()
numberOfBeepers += 1
return numberOfBeepers

countMoreBeepers = True
countBeepers = 0
totalBeepers = amntOfBeepers
while countMoreBeepers:
#move_around()
countBeepers = countBeepers + move_around()
print countBeepers
if countBeepers == totalBeepers:
print 'I have so many delicious muffins! ^.^'
final_move()
countMoreBeepers = False

turn_off()
``````

It keeps telling me that I cannot use the input string in the beginning. Is that because I have other variables or code in there that prevents the input from working? Is there a completely different input function I'm supposed to use? Please help!

input() function means you can input int number or string with " ":
like:

a=input()
"hello"
a
'hello'
a=input()
100
a
100

your code except a int number but not a string var.

## All 2 Replies

input() function means you can input int number or string with " ":
like:

a=input()
"hello"
a
'hello'
a=input()
100
a
100

your code except a int number but not a string var.

Depending on your version of Python: 2.x or 3.x this applies:
2.x:

``````x = raw_input("Beeps: ") #gets the input as a string
try:
x=int(x) #tries to convert it to an int
except Exception as e:
print "Not an int." #if it fails an error message is shown
``````

3.x:

``````x = input("Beeps: ") #gets the input as a string
try:
x=int(x) #tries to convert it to an int
except Exception as e:
print ("Not an int.") #if it fails an error message is shown
``````

This is a simple validation to see if the inserted element is a string or an int. Put it after the `x = input()` part of your program, and see the results.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.