February 18th, 2013, 04:20 PM
Join Date: Feb 2013
Time spent in forums: 13 m 29 sec
Reputation Power: 0
Learning python, help please
I have just recently began learning python (I already know Java), and I am using the google class as I go. I've been having trouble getting python to recognize my if statements and act on them. Here's an example.
# B. both_ends
# Given a string s, return a string made of the first 2
# and the last 2 chars of the original string,
# so 'spring' yields 'spng'. However, if the string length
# is less than 2, return instead the empty string.
# +++your code here+++
if s >= 2:
p1 = s[0:2]
p2 = s[-2:]
tot = p1 + p2
else: tot = ''
When the input is 'a', the program actually uses the first if statement and it returns 'aa', when it should actually return an empty string. Does anyone know what the problem is?