I am new to python. I am trying to make a small elavator program.
The code:
import time
elavator = True
# 0 is B floor // basement
elavatorFloors = [0,1,2,3,4,5]
while elavator == True:
getLevel = input ("Which floor would you like to visit? ( 1 - 5) ")
time.sleep(2)
print "you're now at floor, " +int.getLevel
I get this error: AttributeError: type object ‘int’ has no attribute ‘getLevel’
Aside from changing the str to int, am I using any bad technique? I really want to improve my programming thinking and code writing. Thank you 🙂
int()is a type, so to instantiate it, you need to doint(getLevel), notint.getLevel.Check the docs for examples and more.
Also note that
getLevelis an odd name for the variable, as it implies it is a function that gives the level. A better name would be justlevel.It’s also worth noting that
input()evaluates the input as Python code (In Python 2.x, in 3.x it acts asraw_input()does in older versions), sogetLevelwill already be a number, although I would recommend usingraw_input()instead, and keeping your conversion from a string to an integer, as it won’t allow arbitrary execution of code, which is much better.