-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzad10.py
More file actions
30 lines (24 loc) · 767 Bytes
/
zad10.py
File metadata and controls
30 lines (24 loc) · 767 Bytes
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
# Napisz program, który:
# - utworzy pustą listę i wypełni ją pięcioma liczbami
# losowymi z dowolnego zakresu np. [-1, 1]
# - wypisze po kolei wszystkie elementy listy wraz z
# indeksami w następujący sposób:
# lista[0]: 0.1
# lista[1]: -0.92
# itd.
# - wypisze długość listy, czyli ilość jej elementów
# - znajdzie i wypisze największy element listy oraz
# jego indeks
import random
lista = []
for i in range(5):
lista.append(round(random.uniform(-1, 1)*100)/100)
largest = -10
largestId = 0
for i in range(len(lista)):
print(f"lista[{i}]: {lista[i]}")
if(lista[i] > largest):
largestId = i
largest = lista[i]
print(f"Długość listy: {len(lista)}")
print(f"Największa liczba to: {largest}, a jej indeks to: {largestId}")