-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_length.py
More file actions
41 lines (30 loc) · 1.12 KB
/
check_length.py
File metadata and controls
41 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Write a function named check_length that takes a string as input and:
# Prints the length of the string. Checks if the length is more than 5 characters.
# If yes, print: "Long string" If not, print: "Short string"
def check_length(size):
print("Length of the string is: " , len(size))
if len(size) > 5:
print("Long string")
else:
print("Short string")
check_length("siddarth")
# Write a function called show_name_parts(name) that does the following:
# Prints the first character of the name.
# Prints the last character of the name.
# Prints the first 3 characters.
# Prints the last 3 characters.
def show_name_parts(name):
print("Answer is : ", name[0])
print("Answer is : ", name[-1])
print("Answer is : ", name[0:3])
print("Answer is : ", name[-3:])
show_name_parts("siddarth")
# Write a function check_keyword that takes a string as input.
# If the string contains the word "python", print "Python found!".
# Else, print "Not found".
def check_keyword(name):
if "python" in name:
print("Python found!")
else:
print("Python not found")
check_keyword("i love ")