Skip to content

Commit 6f62481

Browse files
Length of Strings and Error for Integers
1 parent 51b53a3 commit 6f62481

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Functions-and-Conditionals/Functions-and-Conditional-Exercise-01.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
that would generate an error since the len() function doesn't work for integers.
77
88
Modify the function so that if an integer is passed as an input, the function should output a message like "Sorry integers don't have length".
9+
Also, add the conditional block so that floats are counted too.
910
'''
10-
1111
def string_length(mystring):
12-
if type(mystring) == int:
12+
if type(mystring) == int:
1313
return "Sorry, integers don't have length"
14+
elif type(mystring) == float:
15+
return "Sorry, floats don't have length"
1416
else:
1517
return len(mystring)
18+
19+
print(string_length(5))
20+
print(string_length(50.5))
21+
print(string_length("Code"))

0 commit comments

Comments
 (0)