Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

done on IDLE Python 3.11 plz 1. Open a new Python file and name it loops_and_lists.py. 2. Create a list called numbers containing five integers

done on IDLE Python 3.11 plz
image text in transcribed
image text in transcribed
1. Open a new Python file and name it "loops_and_lists.py". 2. Create a list called numbers containing five integers of your choice. 3. Use a for loop to iterate through the numbers list. 4. Inside the loop, print each number with an appropriate message, such as "Number: [number]". Task 2: Modifying List Elements with a for Loop 1. Extend Task 1 by updating the numbers list using a for loop. 2. For each element in the numbers list, multiply it by 2 and update the element in the list. 3. Print the updated numbers list after the loop. Task 3: Using a whi le Loop with Lists 1. Create a new list called fruits containing the names of three fruits of your choice. 2. Use a whi le loop to iterate through the fruits list and print each fruit's name, each on a separate display line. Task 4: Finding Elements in a List with whi le Loop 1. Extend Task 3 by adding a variable search_fruit and assign it the name of a fruit from the fruits list. 2. Use a while loop to check if search_fruit is in the fruits list. 3. If the fruit is found, print "Yes, [search_fruit] is in the list." 4. If the fruit is not found, print "No, [search_fruit] is not in the list." Task 5: Creating a List Using append ( ) 1. Create an empty list called even_numbers. 2. Use a for loop to iterate through the range from 1 to 10. 3. Inside the loop, check if the number is even (i.e., divisible by 2 ). 4. If the number is even, use the append ( ) function to add it to the even_numbers list. 5. Print the even_numbers list after the loop

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions