-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem 5_of_higher_level.py
More file actions
48 lines (39 loc) · 1.58 KB
/
Problem 5_of_higher_level.py
File metadata and controls
48 lines (39 loc) · 1.58 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
41
42
43
44
45
46
47
48
#q no.5 .Given two strings as input, find out if these are the same or not (allowing for maximum one mismatch).
def string_same_check(strg1, strg2):
'''Fiirstly we should check whether the length of
both the taken input string is same or not then check character .
Examples:
>>> string_same_check('swati' ,'swate')
'same'
>>>string_same_check('Bhaiya' , 'Bhaiji')
'not same'
Parameters:
strg1 : first string
strg2 : Second string
Returns:
'same' :if atmost one mismatch in stg1 and strg2.
'not same' : if more than one mismatch in strg1 and strg2.
'''
def get_length(string):
length=0
for char in string:
length=length+1
return length
if get_length(strg1)== get_length(strg2):
mismatch_count_char = 0
length_strg= get_length(strg1)
# Now we will compare character by character by usinng inndexes.
for char in range(length_strg):
if strg1[char] != strg2[char]:
mismatch_count_char= mismatch_count_char+1
if mismatch_count_char>1:
return 'not same'
return 'same'
else:
return ' length of strings are not same'
print(string_same_check.__doc__)
print(string_same_check('swati','swate'))
print(string_same_check('pen','can'))
print(string_same_check('Bhaiya','Bhaiji'))
print(string_same_check('i am a swati jha','i a a swati jha'))
print(string_same_check('image','imoze'))