.


:




:

































 

 

 

 





( ) . :

.

animal = ["", 1.2, 31]

.

b = list("help") # b=['h', 'e', 'l', 'p']

.

c=[x**2 for x in range(20) if x%3==1]

# c=[1,16,49,100,169,256,361]

 

:

len(s) s

x in s .

x not in s = not x in s

s + s1

s*n n*s n s. n < 0, .

s[i] i- s len(s)+i-, i < 0

s[i:j:d] s i j

min(s) s

max(s) s

s[i] = x i- s x

s[i:j:d] = t i j ( d) () t

del s[i:j:d]

, .

append(x)

count(x) , x

extend(s) s

index(x) i, , s[i] == x. ValueError, x s

insert(i, x) x i-

pop(i) i- ,

reverse() s

sort([cmpfunc]) s. cmpfunc.

list, tuple.

, . , - .

stack() . , .

push(item) . ; .

pop() . , . .

peek() , . , .

isEmpty() . , .

size() . ,

s.isEmpty() [] True
s.push(2) [2]  
s.push('') [2,'']  
s.peek() [2,''] ''
s.push(True) [2,'',True]  
s.size() [2,'',True]  
s.isEmpty() [2,' ',True] False
s.push(3.14) s.push(3.14)  
s.pop() [2,' ',True] 3.14
s.pop() [2,' '] True
s.size() [2,' ']  

 

:

class Stack:

def __init__(self):

self.items=[]

def isEmpty(self):

return self.items=[]

def push(self,item):

self.items.append(item)

def pop(self):

return self.items.pop()

def peek(self):

return self.items[len(self.items)-1]

def size(self):

return len(self.items)

from python.basic.stack import Stack

s=Stack

print(s.isEmpty

s.push(4)

s.push(dog)

print(s.speek())

s.push(True)

print(s.size())

print(s.isEmpty())

print(s.pop())

print(s.pop())

print(s.size())


, . , . (, , ). .

: , , ( ). ( ) . .

. :

A={1,2,3}

set() . set , , , , . :

A = set('')

print(A)

{'', '', '', ''}.

, . , :

A = set('') # A={a, , , , }

B = set('') # ={a, , , , }

print(A==B)

True.

:

a=set() # a

b = {, e, }

c= set('') # ={, , }

d={2*i for i in range(5)} # d={0, 2, 4, 6, 8}

e=set([, , , one, one, ein]) # ={, , one, ein}

len(a). :

print(len(set())) # 5

for

f={1,3,4,7}

for san in f: print(san) # 7 1 4 3

in.

print(3 in {1,3,4,7}) # True

add.

a={1,3,4,7}

a.add(6) # a= {1,3,4,6,7}

pop , . KeyError

list .

:

len(s)

x in s x s

s.isdisjoint(s1)

s==s1

s.issubset(s1) s s1

s.issuperset(s1) s1 s

s.union(s1,s2)

s.intersection(s1,s2,) s

s.difference(s1,s2) s

s.simmetric_difference(s1)

s.copy(s1) .

:

s.update(s1,s2,)

s.intersection_update(s1,s2,)

s.difference_update(s1,s2,)

s.simmetric_difference_update(s1,s2,) ,

s.add(b)

s.remove(b) . KeyError.

s.discard(b)

s.pop()

s.clear()

 


Python , . .

(- -) ( ...) . , . , . , . turtle ().

() :

import turtle #

turtle.reset() #

turtle._root.mainloop() # ,

.

, Python, . () , , .

 

help('turtle'). :

Up() ,

Down() ,

Goto(x,y) (x,y)

Color( )

Width(n)

Forward (n) n

Backward (n) n

Right (k) k

Left (k) k

Circle (r) |r|

Write ()

Clear ()

 

#_*_coding: utf8_*_

import turtle

#

turtle.reset()

turtle.tracer(0)

turtle.width(2) #

#

turtle.up() #

x=0

y=100

turtle.goto(x,y) # (0,100)

turtle.fill(1) #

turtle.color('#ffaa00') #

turtle.down() #

turtle.circle(100) #

turtle.fill(0) #

turtle.color('black')

turtle.circle(100)

turtle.up()

#

x=45

y=50

turtle.goto(x,y)

turtle.down()

turtle.color('#0000aa')

turtle.fill(1)

turtle.circle(7)

turtle.up()

turtle.fill(0)

#

x=45

y=50

turtle.goto(x,y)

turtle.down()

turtle.color('#0000aa')

turtle.fill(1)

turtle.circle(7)

turtle.up()

turtle.fill(0)

#

x=-55

y=-50

turtle.goto(x,y)

turtle.right(45)

turtle.width(3)

turtle.down()

turtle.color('#aa0000')

turtle.circle(80,90)

turtle.up()

#

turtle.right(135)

x=0

y=50

turtle.goto(x,y)

turtle.width(2)

turtle.color('black')

turtle.down()

turtle.forward(100)

#

turtle._root.mainloop()

 

 

turtle.color(color) color;

turtle.penup() , ;

turtle.pendown() , ;

turtle.goto(x, y) x y;

turtle.circle(radius) = radius;

turtle.right(degrees) degrees ;

turtle.left(degrees) degrees ;

turtle.forward(length) = length;

turtle.done() , turtle.

 

import turtle # turtle

:

forward(n) # n

backward(n) # n

left(n) # n

right(n) # n

circle(r) # r, , r>0, , r<0

circle(r,n) # r, n , r>0, , r<0

goto(x,y) # (x,y)

:

down() #

up() #

width(n) # n

olor(s) # s # : "red", "blue"

begin_fill(),end_fill() # ( )

:

reset() # ,

lear() #

write(s) # s

radians() #

degrees() #

mainloop() #

tracer(f) #

, :

Aqua, blue, fuchsia, green, maroon, orange, pink, purple, red, yellow, violet, indigo, chartreuse, lime, import turtle # turtleturtle.color("black") # turtle.penup() # turtle.goto(-110, -25) # turtle.pendown() # turtle.circle(45) # 45turtle.color("black")turtle.penup()turtle.goto(0, 80)turtle.pendown()turtle.write("ҮӘӘ") # " ҮӘӘ"

import turtleturtle.penup()turtle.width(3) # turtle.right(90) # 90 . turtle.goto(40, 40)turtle.pendown()turtle.forward(70) # 70turtle.right(90)turtle.forward(70)turtle.right(90)turtle.forward(70)turtle.right(90)turtle.forward(70)turtle.done()

import turtleturtle.begin_fill()turtle.penup()turtle.goto(0,0)turtle.pendown()turtle.forward(60) # 70turtle.right(120) # 120 . turtle.forward(60)turtle.right(120)turtle.forward(60)turtle.end_fill()turtle.done()

from turtle import *
color('orange', 'red')
width(3)
begin_fill()
while True:
forward(250)
left(144)
if abs(pos()) < 1:
break
end_fill()
done()

:

  1. .
  2. .
  3. .
  4. .
  5. .
  6. .

Canvas

: anvas(root,width=w,height=h,bg="blue", \ cursor="pencil") # canv.create_line(0,0,30,50,width=3,fill="blue", \ arrow=LAST) # canv.create_rectangle(x,y,x+8,y+5,fill="red", \ outline="red") # canv.create_polygon([250,100],[200,150],[300,150], \ fill="red")canv.create_oval([20,200],[150,300],fill="gray50") # from math import *
from tkinter import *
root = Tk()
canv = Canvas(root, width = 100, height = 100, \ bg = "lightblue", cursor = "pencil")
canv.create_line(50,100,50,0,width=2,arrow=LAST)
canv.create_line(0,50,100,50,width=2,arrow=LAST)
canv.pack()
root.mainloop()

from math import * from tkinter import *root = Tk()canv = Canvas(root, width = 1000, height = 1000, \ bg = "white")canv.create_line(500,1000,500,0,width=2,arrow=LAST)canv.create_line(0,500,1000,500,width=2,arrow=LAST)First_x = -500 for i in range(16000): if (i % 800 == 0): k = First_x + (1 / 16) * i canv.create_line(k+500,-3+500,k+500,3+500, \ width=0.5, fill= 'black') canv.create_text(k+515,-10+500,text=str(k), \ fill= "purple", \ font=("Helvectica", "10")) if (k!= 0): canv.create_line(-3+500,k+500, \ 3+500,k+500,width=0.5,\ fill = 'black') canv.create_text(20+500,k+500,text=str(k), \ fill= "purple", \ font=("Helvectica", "10")) try: x = First_x + (1 / 16) * i new_f = f.replace('x', str(x)) y = -eval(new_f) + 500 x += 500 canv.create_oval(x, y, x + 1, y + 1, fill = \ 'black' ) except: pass for i in range(1600): canv.create_line(i-1, \ 500+int(sin((i-321)/180*3.14) *200), \ i,500+int(sin((i-320)/180*3.14) *200), \ width=0.5, fill= 'black')canv.pack()root.mainloop()

 

 

Canvas () tkinter, . , , (, , , ). . ( ) . , canvas GUI- c tkinter ( , , , .).

- tkinter . :

from tkinter import *
root = Tk()
canv = Canvas(root,width=600,height=600,bg="white",cursor= "pencil")

.

(0,0) Canvas . ( ).

create_line.

canv.create_line(200,50,300,50,width=3,fill="blue")
canv.create_line(0,0,100,100,width=6,arrow=LAST,fill="orange")

, . (200,50), (300,50). (0,0), (100,100). fill , arrow ( , ).

canv.create_line(500,600,500,0,width=4,arrow=LAST)canv.create_line(0,500,600,500,width=4,arrow=LAST)

create_rectangle . . , .

x = 70y = 110canv.create_rectangle(x,y,x+80,y+50,fill="white",outline="blue")

outline .

.

canv.create_polygon([250,100],[200,150],[300,150],fill="red")

( ). smooth .

canv.create_polygon(300,80,400,80,450,75,450,200,300,180,330, 160,outline="brown",smooth=0,width=4)canv.create_polygon(300,380,400,380,450,375,450,500,300,480,330, 460,outline="orange",smooth=1,width=4)

, .

canv.create_oval([20,200],[150,300],fill="pink")

create_arc. style ( ), (CHORD) (ARC). - , , , . start extent .

canv.create_arc(160,230,230,330,start=0,extent=240, fill="lightgreen")canv.create_arc(250,230,320,360,start=30,extent=300,style=CHORD, fill="green",width=5)canv.create_arc(340,230,410,330,start=0,extent=140,style=ARC, outline="darkgreen",width=2

canvas, .

canv.create_text(20,430,text="ӘӘ",font="arial 36", anchor="w",justify=CENTER,fill="darkred")

anchor (). . , , , w ( . west ). : n, ne, e, se, s, sw, w, nw. , , ( ). justify .

, . :

y=10while y<450: canv.create_rectangle(520,y,570,y+50,fill="lightgrey") canv.create_line(y,520,y+50,570,fill="green",width=10) canv.create_line(y+50,520,y,570,fill="darkgreen",width=10) y = y + 60

canv.pack()
root.mainloop()

:

 

1.

a) y=cos(x)

b) y=x2

c) y=abs(x)

2.

a) .

b) ө .

 


 

: .

, , .

. , . .

. .

X=int(input())

print(1/X)

2

0

try:

#

except: # except : -

# ,

else: #

# ,

finally:

# ,

try:

X=int(input())

print(1/X)

except:

print(Error dividing by zero)

raise , .

 


Python . __ ( __myprivatevar). . :

 

class Myclass:

common = 10

def __init__(self):

self. myvariable = 3

def myfunction (self, arg1, arg2):

return self. myvariable

# Myclass.

# __init__ .

classinstance = Myclass ()

# myvariable 3

classinstance.myfunction(1, 2)

# myfunction Myclass myvariable

3

# common

classinstance2 = Myclass ()

classinstance.common # 10

classinstance2.common # 10

# , Myclass

# , Myclass

Myclass.common = 30

classinstance.common # 30

classinstance2.common # 30

# .

#

classinstance.common = 10

classinstance.common # 10

classinstance2.common # 30

Myclass.common = 50

#

#

classinstance.common # 10

classinstance2.common # 50

# Myclass,

# ,

# , : class Otherclass(Myclass1, Myclass2,

# MyclassN)

class Otherclass (Myclass):

def __init__(self, arg1):

self.myvariable = 3

print arg1

classinstance = Otherclass("hello")

hello

classinstance.myfunction(1, 2) # 3

# test,

# .

# classinstance.

classinstance. test = 10 # classinstance.test 10

 

Python try-except [exceptionname]:

def somefunction():

try:

10 / 0 #

Except ZeroDivisionError:

# " "

# ZeroDivisionError

Print "Oops, invalid."

fnexcept ()

Oops, invalid.


1. http://younglinux.info/book/export/html/48

2. http://younglinux.info/tkinter/canvas.php

3.


 

-------------------------------------------------

C4-0-1.

Python 3.

: , 2013

E-mail: [email protected]

Web: kpolyakov.spb.ru

-------------------------------------------------

N, N :

<> <> < >

<> , 20 ,

<> , 4- (, , ,

), < > . <>

<>, <> < > . :

.. 57

, , ( ). , . , N>=1000.

"""

import sys

save_stdin = sys.stdin

sys.stdin = open("in/0-1.in")

N = int(input())

schCount = {}

for i in range(N):

fam, io, school = input().split()

schCount[school] = schCount.get(school, 0) + 1

minCount = min(schCount.values())

schMin = [x[0] for x in list(schCount.items()) if x[1] == minCount]

for x in sorted(schMin):

print(x)

sys.stdin = save_stdin

 


 

 

del .

Python . . for , if .

lst1 = [1, 2, 3]

lst2 = [3, 4, 5]

print [x * y for x in lst1 for y in lst2] # [3, 4, 5, 6, 8, 10, 9, 12, 15]

print [x for x in lst1 if 4 > x > 1] # [2, 3]

# any true, ,

# , .

any (i % 3 for i in [3, 3, 4, 4, 3])

True

#

#

sum(1 for i in [3, 3, 4, 4, 3] if i == 3) # 3

del lst1[0]

print lst1 # [2, 3]

del lst1

N = int(input()) sum = 0 while N > 0: d = N%10 sum += d N = N // 10 print(sum) N = int(input()) sum = 0 while N > 0: sum += N%10 N = N // 10 print(sum)

x = int(input())

cnt = 0

while x > 0:

cnt += 1

x //= 10

print(cnt)

 

x = int(input())

cnt = 0

while x > 0:

cnt += x % 2

x //= 2

print(cnt)

 

N = int(input()) maxD = N % 10 while N > 0: d = N % 10 if d > maxD: maxD = d N //= 10 print(maxD) s= input() S=list(s) print(max(S)) print(max(list(input())))

 

mx = s = 0

for i in range(1, 5):

x = int(input())

if x < 0: s += x

if x > mx: mx = x

print(s,mx)

1. , . , .

x=input() A=[0,0,0,0,0,0,0,0,0,0] i=0 while(x[i]!='.'): if x[i]>='0' and x[i]<='9': A[int(x[i])]+=1: i+=1 for z in range(9,-1,-1): print(z*A[z],end='') var a:array['0'..'9'] of integer; i,j,k:integer; c:char; begin for c:='0' to '9' do a[c]:=0; repeat read(c): if c in ['0'..'9'] then a[c]:=a[c]+1 // if (c>='0') and (c<='9') then a[c]:=a[c]+1 until c='.'; for c:='9' downto '0' do for i:=1 to a[c] do write(c) end.

2. N N . . 21.

N = int(input())

M3 = M7 = M21 = M = 0

for i in range(N):

x = int(input())

if x % 21!= 0:

if x % 3 == 0: M3 = max(M3, x)

if x % 7 == 0: M7 = max(M7, x)

if x % 21 == 0 and x > M21:

M = max(M21, M)

M21 = x

else:

M = max(M, x)

R = max(M3*M7, M21*M)

print(" - ", R)

R0 = int(input())

if R == R0: # if int(input()) == R0:

print(" ")

else:

print(" ")

3. 11. : F G:

def F(n):

if n > 0:

G(n - 1)

def G(n):

print('*')

if n > 1:

F(n - 2)

F(11)?

4. 20

x = int(input())

L = x-45

M = x+45

while L!= M:

if L > M: L = M

else: M = L

print(M)


 

http://pythonworld.ru/samouchitel-python

https://habrahabr.ru/post/29778/

 


[1] .

[2] . in: X in A, true , false.

[3] var x,y,z,i,j,n1,n2,n3:word; a,b,c:string;

begin

read(c);

a:=copy(c,1,pos(' ',c)-1);delete(c,1,pos(' ',c)); x:=length(a);

b:=copy(c,1,pos(' ',c)-1); delete(c,1,pos(' ',c)); y:=length(b);

z:=length(c);

if ((x>y) or (x=y) and (a>b)) and ((x>z) or (x=z) and (a>c)) then write(a)

else if (z>y) or (z=y) and (c>b) then write(c) else write(b)

end.

[4]

Var i,j,p:longint; a,b,c:string;

begin

readln(a); read(b); i:=length(a); j:=length(b);

c:=''; p:=0;

while (i>0) and (j>0) do begin

p:=p+ord(a[i])+ord(b[j])-96;

c:=chr(p mod 10+48)+c;

p:=p div 10;

i:=i-1; j:=j-1;

end;

if i=0 then

while j>0 do begin

p:=p+ord(b[j])-48;

c:=chr(p mod 10+48)+c;

p:=p div 10; j:=j-1;

end

else

if j=0 then

while i>0 do begin

p:=p+ord(a[i])-48;

c:=chr(p mod 10+48)+c;

p:=p div 10; i:=i-1;

end;

c:=chr(p+48)+c;

while (c[1]='0') and (length(c)>1) do delete(c,1,1);

write(c)

end.





:


: 2016-12-05; !; : 501 |


:

:

: , .
==> ...

772 - | 734 -


© 2015-2024 lektsii.org - -

: 0.397 .