Attachment '2012-11-23.findnum.py'
Download 1 #!/usr/bin/env python
2 # coding: utf
3 '''
4 Написать функцию поиска числа (последовательности цифр, ограниченной началом, концом строки или пробелами) в строке, ввести строку и три числа, вывести, какие числа в строке встречаются
5
6 Решить ту же задачу для строки и списка чисел произвольной длины.
7 '''
8
9 def findnumN(n, s):
10 '''Поиск числа n в строке s (вручную)'''
11 b, S = 0, s+" "
12 for i in xrange(len(S)):
13 if S[i] == " ":
14 if str(n) == S[b:i]:
15 return True
16 b = i
17 return False
18
19 def findnum(n, s):
20 '''Поиск числа n в строке s'''
21 return str(n) in s.split()
22
23 s=raw_input("Введите строку: ")
24 l=input("Введите более одного числа через запятую: ")
25 for el in l:
26 print "{0}{1}присутствует в строке".format(el, findnum(el, s) and " " or " не ")
27 for el in l:
28 print "{0}{1}присутствует в строке".format(el, findnumN(el, s) and " " or " не ")
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.- [get | view] (2012-11-30 12:24:38, 1.2 KB) [[attachment:2012-11-23.AtoB.py]]
- [get | view] (2012-11-30 12:24:07, 1.2 KB) [[attachment:2012-11-23.findnum.py]]
- [get | view] (2012-12-14 08:59:28, 2.2 KB) [[attachment:2012-11-23.slagaemye.py]]
- [get | view] (2012-11-30 12:24:53, 1.6 KB) [[attachment:2012-11-23.sort2.py]]
- [get | view] (2012-11-30 12:25:07, 1.7 KB) [[attachment:2012-11-23.sort2.rnd.py]]
You are not allowed to attach a file to this page.