Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following program creates a list of odd integers, whose range depends on user's choice: print( This program creates a list of odd numbers in

The following program creates a list of odd integers, whose range depends on user's choice:

print("This program creates a list of odd numbers in the range of your choice.") start_num = int(input("Enter starting number: ")) end_num = int(input("Enter ending number: ")) my_list = [] for i in range(start_num, end_num+1): if i % 2 == 1: my_list.append(i) print("odd numbers in the range:", my_list)

The program above creates an empty list first and then uses a loop to append odd integers to the list. We can shorten the program by using generator expression. Use one single statement to generate the whole list of odd integers. You must use generator expression in that statement. No loop is allowed in the program.

The following is sample test run.

This program creates a list of odd numbers in the range of your choice.

Enter starting number: 11

Enter ending number: 21

Odd numbers in the range: [11, 13, 15, 17, 19, 21]

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

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions