Hi
Im working with a python Odd numbers and my question is?.

An integer can either be odd (like 1,3,5,7,. . . ) or even (2,4,6,8,. . . ).

1. Write a python code which takes as input two numbers and displays all odd numbers between them (and inclusive them) sorted according their value. As example, ff the two inputs are 40 and 33, the results should be: 33 35 37 39
2. Generate a new list by mapping on each element x of the list (the one generated by the previous question) the function x ? x - 30 ? x - 13.
3. Display numbers which are member of both lists?

Edited by pyTony: fixed formatting

2
Contributors
6
Replies
94
Views
4 Years
Discussion Span
Last Post by tony75

As much as we would like to help you, we must see that you've tried first. Show us the code you have so far.

Spoiler alert: there aren't any numbers which are in both lists.

Edited by Lucaci Andrew

Thank Sir
actully Im not understand question 2(2.Generate a new list by mapping on each element x of the list )
to do it?

You have your odd list, right?
So you'll parse that list, and for each element you apply the equation, and store the result in the 2nd list:

``````secondList = []
for i in listOfOddNumbers:
secondList.append(i * i - 30 * i - 13)
``````

This is a short example:

``````'''
Numbers:
\\: 40
\\: 33
First list:  [33, 35, 37, 39]
Second list:  [86, 162, 246, 338]
'''
``````

And, as you can see:

``````i * i - 30 * i - 13
``````

will always produce even numbers, so, there aren't any numbers which can be in both lists.

Edited by Lucaci Andrew

Thanks
bt the way

How can I display numbers of this new list which are between the two numbers?

Edited by tony75

Having your numbers inputed, called for example `nr1` and `nr2`, you parse the new list and print those who are between them:

``````nr1, nr2 = 33, 40
lst = [20,34,37,41,46,50,65,67,87]
for i in lst:
if nr1 < i < nr2: print i
``````

Thank you very much.

Edited by tony75