I am trying to write a Python (2.7.3) program that would check a list to see if a the value of a placing for a list has been given or not?
input = raw_input("(Enter three numbers separated by commas) >: ")
input_list = input.split(" ")
replacing_letters = [str(x.strip(" ")) for x in input_list]
'if replacing_letters[2] is blank:'
print"Incomplete"
'elif replacing_letters[2] is full':
print replacing_letters
So if I were to enter three numbers into an input, it would print the list to the user. But say I were to only input two numbers. It would return to the user 'Incomplete'.
Any suggestions on a method or code to accomplish this?
You can get the length of a list with the len()
built-in function . You can then do a simple check against this:
if len(input_list) <= 2:
...
else:
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.