Предмет: Информатика, автор: drtrhwewfj

Язык программирования Python

1. Напишіть цикл for, щоб кожен елемент у списку друкувався.
lst=["koala", "cat", "fox", "panda", "chipmunk", "sloth", "penguin", "dolphin"]

2.Напишіть цикл for, який друкує "Hello! " плюс кожне ім'я у списку. тобто: "Hello!, Sam"
lst=["Sam", "Lisa", "Micha", "Dave", "Wyatt", "Emma", "Sage"]

3.Напишіть цикл for, який перебирає рядок і друкує кожну літеру.
string = "Antarctica"

4.Використовуючи цикл for і метод .append(), додайте кожен елемент із префіксом Dr. до lst2.
lst1=["Phil", "Oz", "Seuss", "Dre"]
lst2=[]

5. Напишіть цикл for, який додає квадрат кожного числа до нового списку.
lst1=[3, 7, 6, 8, 9, 11, 15, 25]
lst2=[]

6. Напишіть цикл for, використовуючи оператор if, який додає кожне число до нового списку, якщо воно додатне.
lst1=[111, 32, -9, -45, -17, 9, 85, -10]
lst2=[]

7.Напишіть цикл for, який додає тип кожного елемента з першого списку до другого списку.
lst1=[3.14, 66, "Teddy Bear", True, [], {}]
lst2=[]

Ответы

Автор ответа: nazikmuz
1

1. Напишіть цикл for, щоб кожен елемент у списку друкувався.

lst=["koala", "cat", "fox", "panda", "chipmunk", "sloth", "penguin", "dolphin"]

Відповідь:

Python code:

lst=["koala", "cat", "fox", "panda", "chipmunk", "sloth", "penguin", "dolphin"]

for i in range (0,8):

   print(lst[i])

2.Напишіть цикл for, який друкує "Hello! " плюс кожне ім'я у списку. тобто: "Hello!, Sam"

lst=["Sam", "Lisa", "Micha", "Dave", "Wyatt", "Emma", "Sage"]

Відповідь:

Python code:

lst=["Sam", "Lisa", "Micha", "Dave", "Wyatt", "Emma", "Sage"]

for i in range(0,7):

   print("Hello!,",lst[i])

3.Напишіть цикл for, який перебирає рядок і друкує кожну літеру.

string = "Antarctica"

Відповідь:

Python code:

string = "Antarctica"

for letter in string:

   print(letter)

4.Використовуючи цикл for і метод .append(), додайте кожен елемент із префіксом Dr. до lst2.

lst1=["Phil", "Oz", "Seuss", "Dre"]

lst2=[]

Відповідь:

Python code:

lst1=["Phil", "Oz", "Seuss", "Dre"]

lst2=[]

for i in range(0,4):

   string = "Dr." + lst1[i]

   lst2.append(string)

print(lst2)'

5. Напишіть цикл for, який додає квадрат кожного числа до нового списку.

lst1=[3, 7, 6, 8, 9, 11, 15, 25]

lst2=[]

Відповідь:

Python code:

lst1=[3, 7, 6, 8, 9, 11, 15, 25]

lst2=[]

for i in range(0,8):

   lst2.append(lst1[i] * lst1[i])

   

print(lst2)

6. Напишіть цикл for, використовуючи оператор if, який додає кожне число до нового списку, якщо воно додатне.

lst1=[111, 32, -9, -45, -17, 9, 85, -10]

lst2=[]

Відповідь:

Python code:

lst1=[111, 32, -9, -45, -17, 9, 85, -10]

lst2=[]

for i in range(0,8):

   if(lst1[i] > 0):

       lst2.append(lst1[i])

       

print(lst2)

7.Напишіть цикл for, який додає тип кожного елемента з першого списку до другого списку.

lst1=[3.14, 66, "Teddy Bear", True, [], {}]

lst2=[]

Відповідь:

Python code:

lst1=[3.14, 66, "Teddy Bear", True, [], {}]

lst2=[]

for i in range(0,6):

   lst2.append(type(lst1[i]))

   

print(lst2)

Похожие вопросы
Предмет: Английский язык, автор: milanamanyukova
Найти все неправильные глаголы в тексте.

One day in 1777, Joseph Montgolfier was relaxing in front of the fire with his laundry drying nearby. After a while, he noticed that one of his shirts started to float upwards. The young man was curious about what happening, so he threw some small pieces of paper into the fireplace to see if the same thing happened to them. When he saw them coming out of the chimney, he came to the conclusion that smoke had the power to lift up and carry them through the air. Joseph loved science and wanted to become an inventor, so he started trying to think of a craft that would be able to capture smoke and heat and lift people off the ground. Along with his brother Jacques, he began performing experiments on something that later became the first hot-air balloon.



The Montgolfier brothers quickly realised that it was heat and not smoke that had the power to lift things. On 19th September 1783, they presented their first hot-air balloon, which was made from paper and cloth. They burned some straw underneath it and the heat helped the balloon to float. As this was its first trip, the Montgolfier brothers were too nervous to go up in the balloon themselves. So, instead they put a sheep, a duck and a chicken in the basket that hung below the balloon for the two-mile journey.



The new invention was a great success and the animals landed safe and sound. A huge crowd, including some members of the French Royal Family gathered to watch the balloon floating high in the sky. Shortly afterwards, brothers asked the king for permission to send men up in the balloon. The King agreed, and the first flight consisting of human passengers took place in Paris on 21st November 1783 with great success. The balloon reached heights of around 150 metres as it floated over the Paris rooftops, starting a long tradition of hot-air ballooning.