.


:




:

































 

 

 

 





print(" "); # a = int(input()); print(" "); # b = int(input()); c = a + b; print(" = ", c);

 

 

#C fruits_list
fruit_list = [ 'apple', 'bannana', 'pie', 'potatoe' ];

fruit_list[1] = 'cherry'; #
print(fruit_list); #

#
fruit = fruit_list[2]; # fruit pie
print(fruit); # pie


#
print(fruit_list[2]); # pie


#
print(fruit_list[1:]); # ['cherry', 'pie', 'potatoe']


#
print(fruit_list[:2]); # ['apple', 'cherry']


#
print(fruit_list[1:3]); # ['cherry', 'pie']

 

# list
list = [ 'apple', 'bannana', 'pie', 'orange' ];


#
list.append('pineapple');
print(list); # ['apple', 'bannana', 'pie', 'orange', 'pineapple'];


#
del list[2];
print(list); # ['apple', 'bannana', 'orange', 'pineapple']


# bannana
list.insert(0, 'mango');
print(list); # ['mango', 'apple', 'bannana', 'orange', 'pineapple']


#
list.sort();
print(list); #['apple', 'bannana', 'mango', 'orange', 'pineapple']


#
x = len(list);
print("Len = %d" % x); #Len = 5


#'

vegetable_list = [ 'potatoe', 'cabbich', 'carrot', 'onion' ];
new_list = list + vegetables_list;
print(new_list); # ['apple', 'bannana', 'mango', 'orange', 'pineapple', 'potatoe', 'cabbich', 'carrot', 'onion']

 

#
fruit_list = [ 'apple', 'bannana', 'pie', 'orange' ];

#
bucket = [fruit_list, vegetable_list];
print(bucket);
#
print(bucket[0][1]); # bannana
print(bucket[1][3]); # onion

 


 

 

: if, elif, else.

: ==,!=, >, >=, <, <=.

.

 

age = 21;
if age > 16:
print("Your are old enough to drive.")
else:
print("Yor are NOT old enough to drive.")

if ((age >= 1) and (age <= 18)):
print("You study in school")
elif (age == 21):
print("You graduate from school")
elif not (age > 21):
print("You still have to study a bit");
else:
print("");

 

for:

 

for x in range(0,10):
print(x, end= " "); # 0 1 2 3 4 5 6 7 8 9

for x in [ "a", "b", "c", "d", "e", "f" ]:
print(x, end= " "); # a b c d e f

numbers = [0,1,2,3,4,5,6];
for x in numbers:
print(x, end= " "); # 0 1 2 3 4 5 6

 


numbers = [[1,2,3],[10,20,30],[100,200,300]];
for i in range(0,3):
for j in range(0,3):
print(numbers[i][j], end= " "); # 1 2 3 10 20 30 100 200 300

for subList in numbers:
for number in subList:
print(number, end= " "); # 1 2 3 10 20 30 100 200 300

 

# : import random

# 0 100

random_number = random.randrange(0,100);

 

while:

random_number = 0;
while (random_number!= 15):
random_number = random.randrange(0,100);
print(random_number);


i = 0;
while (i<10):
print(i, end= " ");
i = i + 1;
# 0 1 2 3 4 5 6 7 8 9
i = 0;
while (i < 10):
print(i, end= " ");
i = i + 1;
if (i == 5):
break;
# 0 1 2 3 4

i = 0;
while (i < 10):
i += 1; # i = i + 1;
if (i == 5):
continue;
print(i, end= " ");
# 1 2 3 4 6 7 8 9 10

 

#
def sumNumbers(a, b):
sum = a + b;
return sum;

 

# sum
sum = sumNumbers(3, 4);
print(sum); # 7
#
print(sumNumbers(3, 4)); # 7

.

, 10 , , .

(Selection sort), (Bubble sort), (Insertion sort) (Cocktail shaker sort).





:


: 2017-03-12; !; : 316 |


:

:

,
==> ...

1862 - | 1636 -


© 2015-2024 lektsii.org - -

: 0.011 .