48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
nasze_dane = ( 23, 44, 55, 44, 34, 76, 87)
|
|
|
|
for element in nasze_dane:
|
|
if type(element) is str:
|
|
break
|
|
wynik = round(element / 6,3)
|
|
print(f"Wynik dzielenia to {wynik}")
|
|
|
|
else:
|
|
print("Wszystko ok")
|
|
|
|
##
|
|
|
|
nasze_dane = ( 23, 44, 55, 44,"A", 34, 76, 87)
|
|
|
|
for element in nasze_dane:
|
|
if type(element) is str:
|
|
continue
|
|
wynik = element / 6
|
|
print(f"Wynik dzielenia to {wynik}")
|
|
|
|
else:
|
|
print("Wszystko ok, nawet gdy continue")
|
|
|
|
|
|
# Zadanie:
|
|
# masz dane wejściowe: nasze_dane = (1,2, "Linux", True, 3.44, "Adam")
|
|
# przed pętlą zrób listę wyniki = []
|
|
# napisz pętlę for, a w bloku kodu zrób tak:
|
|
# jeśli element to str lub int, to dodaj go do listy wyniki
|
|
# na końcu pętli wyświel wyniki
|
|
|
|
# jedno z możliwych rozwiązań:
|
|
|
|
nasze_dane = (1,2, "Linux", True, 3.44, "Adam")
|
|
wyniki = []
|
|
|
|
for element in nasze_dane:
|
|
|
|
# if type(element) is str or type(element) is int:
|
|
# wyniki.append(element)
|
|
|
|
if type(element) is str:
|
|
wyniki.append(element)
|
|
elif type(element) is int:
|
|
wyniki.append(element)
|
|
|
|
print(wyniki) |