from random import randint
# заполняем массив случайными числами
arr = [randint(-10,10) for i in range(20)]
print(arr)
# задание 1
print(f'Сумма элементов первой половины массива {arr[0:10]} равна {sum(arr[0:10])}')
print(f'Сумма элементов второй половины массива {arr[10:20]} равна {sum(arr[10:20])}')
# задание 2
k=1
for i in arr:
if i!=0:
k*=i
print(f'Произведение ненулевых элементов массива равно {k}')
# задание 3
k=0
for i in arr:
if i<0:
k+=1
print(f'Количество отрицательных элементов массива равно {k}')
import java.util.Scanner;
public class TreeStructures {
static Scanner scnr = new Scanner(System.in);
static int height;
public static void main(String[] args) {
System.out.print("How tall should the top of the tree be? ");
height = scnr.nextInt();
System.out.println();
if (height >= 5 && height <= 20) {
System.out.println("Flat tree:");
flatTree();
System.out.println("Xmas tree:");
xmasTree();
} else {
System.out.println("That's not a valid size. I can only do trees from 5 to 20");
System.out.println("Quitting now.");
}
}
public static void flatTree() {
int width = (height * 2) - 1;
// first for loop to print number of rows
for (int i = 1; i <= height; i++) {
// second for loop to print stars to create rectangle
for (int stars = 1; stars <= width; stars++) {
System.out.print("*");
}
// println to print rows in.
System.out.println();
}
//first for loop to print out rows for the bottom part of tree
for (int i = 0; i <= height / 5; i++) {
if (height % 2 == 0) {
for (int j = 0; j <= ((width) / 3) + 1; j++) {
System.out.print("*");
}
} else {
//second for loop to print out width for the bottom part of the tree
for (int j = 0; j <= (width) / 3; j++) {
System.out.print("*");
}
}
System.out.println();
}
}
public static void xmasTree() {
int width = height * 2 - 1;
// NESTED LOOPS
// first for loop to print amount of rows
for (int i = 0; i < height; i++) {
// second for loop for print out spaces to match the tree level
for (int j = 0; j < height - i; j++) {
System.out.print(" ");
}
// third for loop to print out stars
for (int k = 0; k < (2 * i + 1); k++) {
System.out.print("*");
}
System.out.println();
}
// first for loop to determine amount of rows for bottom
for (int i = 0; i <= height / 5 +1 ; i++) {
// for loop to print the bottom part of the tree
for (int j = 0; j <= width/3; j++) {
System.out.print(" ");
}
for (int j = 0; j <= (width) / 3; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
выход:
Flat tree:
Xmas tree:
*
***
Объяснение:
a = []
a0 = int(input('Введите 1 целое число: '))
a1 = int(input('Введите 2 целое число: '))
a2 = int(input('Введите 3 целое число: '))
a3 = int(input('Введите 4 целое число: '))
a4 = int(input('Введите 5 целое число: '))
a5 = int(input('Введите 6 целое число: '))
a6 = int(input('Введите 7 целое число: '))
a7 = int(input('Введите 8 целое число: '))
a8 = int(input('Введите 9 целое число: '))
a9 = int(input('Введите 10 целое число: '))
a.append(a0)
a.append(a1)
a.append(a2)
a.append(a3)
a.append(a4)
a.append(a5)
a.append(a6)
a.append(a7)
a.append(a8)
a.append(a9)
print(a)
b = a.index(min(a))
c = min(a)
a.pop(b)
a.insert(0, c)
d = a.index(max(a))
e = max(a)
a.pop(d)
a.append(e)
print(a)
Объяснение: