# given that p is a non-negative integer, which of these gives positive integers that are multiple of 5?

### Mohammed

Guys, does anyone know the answer?

get given that p is a non-negative integer, which of these gives positive integers that are multiple of 5? from screen.

## python

The program should work as follow: Please type in a number: 5 1 5 2 4 3 My code doesn't do the same. I think there is should be the 2nd loop, but I don't really understand how can I do it. Could you

## How to write the program that prints out all positive integers between 1 and given number , alternating between the two ends of the range?

Ask Question Asked 10 months ago

Modified 4 months ago

Viewed 7k times 0

The program should work as follow:

Please type in a number: 5

1 5 2 4 3

My code doesn't do the same. I think there is should be the 2nd loop, but I don't really understand how can I do it. Could you possibly give me a hint or advice to solve this task. Thanks. My code looks like this:

num = int(input("Please type in a number:"))

n=0 while num>n: a = num%10 num -= a num = num/10 print(a) n = n + 1 print(n)

pythonwhile-loopflip

Share

Improve this question

asked Nov 1, 2021 at 19:45

Denis 431 1 silver badge 6 6 bronze badges

i am trying to understand the question but i am not able to. Can you try to explain the output logic? –

aberkb

Nov 1, 2021 at 19:55

I enter a number, let's say 6, and I want the program show me all integers from 1 to 6 in certain order: 1 6 2 5 3 4 –

Denis

Nov 1, 2021 at 23:45

Add a comment

## 6 Answers

2 This should work:

num = int(input("Please type in a number:"))

number_list = [i+1 for i in range(num)]

while number_list:

print(number_list.pop(0))

number_list.reverse()

Share Improve this answer

answered Nov 1, 2021 at 19:57

Chris J 1,3758 8 silver badges 19 19 bronze badges 2

O(n^2) because of .reverse() –

Marat

Nov 1, 2021 at 20:12

Thanks! I'm beginner in python and stucked with this type of tasks. How it possible to change this code that it shows the sequence in different order like 2 1 4 3 5 (vertically). –

Denis Nov 2, 2021 at 0:01 Add a comment 2 x = flag = 1

for i in range(n-1, -1, -1):

print(x)

flag, x = -flag, x+flag*i

Share Improve this answer

answered Nov 1, 2021 at 20:10

Marat 14.1k2 2 gold badges 37 37 silver badges 45 45 bronze badges 2

Cute, but the degree of head-scratching required seems excessive for this problem. This feels like a perl solution.... –

Jon Kiparsky

Nov 1, 2021 at 20:18

Add a comment 1

Not the most space-efficient way, but if the number is relatively small, an easy approach is to build a list and just pop off either end in turn:

nums = list(range(1, int(input("Please type in a number:"))+1))

while nums: print(nums.pop(0)) if nums: print(nums.pop()) Share Improve this answer

answered Nov 1, 2021 at 19:56

Samwise 57.8k3 3 gold badges 29 29 silver badges 38 38 bronze badges

so many list relocations, why not just use negative index? –

Olvin Roght

Nov 1, 2021 at 19:57

Minimizing the amount of state to keep track of. For a linear-time/constant-space solution I'd use range and zip_longest but that feels out of scope for a beginner question :P –

Samwise

Nov 1, 2021 at 19:59

Add a comment 1

Seemingly the most memory efficient way would be to use itertools.zip_longest and ranges:

from itertools import zip_longest

n = int(input("Please type in a number: "))

for lower, upper in zip_longest(range(1, n // 2 + 1), range(n, n // 2, -1)):

if lower: print(lower) print(upper) Share Improve this answer

answered Nov 1, 2021 at 20:00

Matiiss 5,6562 2 gold badges 12 12 silver badges 27 27 bronze badges Add a comment 1

This is a cute way to do it:

l = list(range(1,6))

def index_generator():

while True: yield 0 yield -1

index = index_generator()

result = [] while l:

result.append(l.pop(next(index)))

Share Improve this answer

edited Nov 9, 2021 at 5:06

answered Nov 1, 2021 at 20:15

Jon Kiparsky 7,2212 2 gold badges 22 22 silver badges 38 38 bronze badges Add a comment 0

number = int(input())

left = 1 right = number while left < right: print(left) print(right) left += 1 right -= 1

# In case of odd numbers

if left == right: print(left)` Share Improve this answer

answered Apr 30 at 15:36

enigmacoder-bot 1 1

Could you explain some of your code, to make it easier to understand for future readers? –

BrokenBenchmark May 1 at 0:25 Add a comment

Not the answer you're looking for? Browse other questions tagged pythonwhile-loopflip or ask your own question.

The Overflow Blog

Five nines uptime without developer burnout (Ep. 488)

We hate Scrum and Agile…when it’s done wrong (Ep. 489)

Featured on Meta

Recent Color Contrast Changes and Accessibility Updates

Reviewer overboard! Or a request to improve the onboarding guidance for new...

Should I explain other people's code-only answers?

### Related

701

How to calculate number of days between two given dates

0

How to terminate this program on while loop and why error message prints out before user input?

## A non

Answer (1 of 3): Set of non negative integers under consideration = S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39} So, n(S) = 40 First qualifier = Q1: non negative integers less than 5. S...

A non-negative integer less than 40 is randomly chosen. What is the probability that it is divisible by either 3 or 4 or it is less than 5?

Ad by Amazon Web Services (AWS)

AWS is how.

AWS removes the complexity of building, training, and deploying machine learning models at any scale.

Sort Jack Smith

Lived in Philadelphia, PAAuthor has 3K answers and 6.6M answer views1y

Non-negative integers less than 40:

x∈[1,39] x∈[1,39]

The integers that qualify:

1, 2, 3, 4, 6, 8, 9, 12, 15, 16, 18, 20, 21, 24, 27, 28, 30, 32, 33, 36, 39

21 39 ⇒ 7 13 2139⇒713 Related questions

What is the probability of a positive integer selected at random not exceeding 100 is divisible by 5 or 7?

An integer is chosen at random from the first 500 positive integers. What is the probability that the integer chosen is divisible by 3, 4, or by 5?

A integer is selected from the first 3 positive integers. What is the probability that it is divisible by 3 or 5?

What is the probability of getting a number less than 5 or divisible by 3?

What is a non-negative integer less than 5?

Marek Čtrnáct

Translator From EnglishAuthor has 175 answers and 55.9K answer views2y

Related

You have nine integers, none of which is divisible by 3. What is the probability that the sum of those 9 integers is divisible by 9 by 3?

If you ask about divisibility of the sum by 3, it can be found like this:

First, we have to ask what does “probability” mean in the context of infinite set of integers. But since we are only interested in divisibility by 3, we can use a naive approach that there is 1/3 chance a randomly chosen integer will be divisible by 3, 1/3 that it will give remainder 1 when divided by 3, and 1/3 that it will give remainder 2.

Since none of our integers is divisible by 3, they all give remainder when divided by 3. This remainder will be 1 or 2, with probability 1/2 for each.

We have 9 integers, so there’s 51

Sponsored by Global USA Green Card

2022 is your year! Register now & get our special offers!

A green card is the best and the fastest ticket to American life. Get a chance to win and apply today!

Alexander Farrugia

Loves numbers.Author has 3.2K answers and 20.7M answer views6y

Related

What is the probability that a randomly chosen positive two-digit integer is a multiple of 3?

I’m going to assume ‘randomly chosen’ to mean ‘every two digit number from

10 10 to 99 99

has an equal likelihood of being chosen’. (Note that it might mean other things, so it’s best to define your probability distribution precisely.)

With that out of the way, the two digit numbers that are divisible by

3 3 are 12,15,18,…,99 12,15,18,…,99

, of which there are

30 30

(how do I know this?). Since there are

90 90

two-digit numbers in all (how do I know this?), the probability of choosing a two-digit number ‘at random’ (with the meaning described above) is

30 90 = 1 3 3090=13 . Phil Scovis

I play guitar. And sing in the car.Upvoted by

Rowan McKee

, B.S. Mathematics & Computer Science, California State University, East Bay (2021)Author has 3.9K answers and 5.8M answer views2y

Related

If all positive integers are possible outcomes, what is the probability that a number chosen at random will be divisible by 5 and 11?

The common expression “chosen at random” is usually interpreted to mean “with a uniform distribution”.

You cannot have a uniform distribution with infinite support. This may seem counter-intuitive, but this is a mathematical fact. Assuming a uniform distribution with infinite support leads to paradoxes such as the Envelope Paradox

, and being sloppy with what distribution you are using leads to things like the Bertrand Paradox

.

However, we can interpret your question in ways that make more sense. For example: In the limit as x approaches infinity, what is the probability that a number chosen unif

Jayanta Mukherjee

B Tech IEE in Instrumentation Engineering, Jadavpur University (Graduated 1990)Author has 12.4K answers and 5.4M answer views1y

Set of non negative integers under consideration = S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}

So, n(S) = 40

First qualifier = Q1: non negative integers less than 5. So, Q1 = {0, 1, 2, 3, 4}. Thus, n(Q1) = 5.

Second qualifier = Q2: integers less than 40 and not smaller than 5 those are divisible by either 3 or 4. M3: Those divisible by 3, M4: Those divisible by 4. Now, M3 = {6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39}, M4 = {8, 12, 16, 20, 24, 28, 32, 36} and (M3 intersect M4) = {12, 2

Sponsored by Grammarly

Communicate effectively throughout your writing universe.

Grammarly for Windows and Mac offers writing feedback in Slack, Word, Gmail, and beyond. Install it now!

Ellis Cave

40+ years as an Electrical EngineerAuthor has 5.1K answers and 2.6M answer views1y

Using the J programming language, brute force approach:

(J (programming language) - Wikipedia

)

J primitives: NuVoc - J Wiki (NuVoc - J Wiki

## If p: when a positive integer and a negative integer are added we always get a negative integer and q: when two negative integers are added, we get a positive integer, then.

Click here👆to get an answer to your question ✍️ If p: when a positive integer and a negative integer are added we always get a negative integer and q: when two negative integers are added, we get a positive integer, then.

Question

## If p: when a positive integer and a negative integer are added we always get a negative integer and q: when two negative integers are added, we get a positive integer, then.

**A**

## Both p and q are true

**B**

## p is true and q is false

**C**

## p is false and q is true

**D**

## Both p and q are false

Easy Open in App

Updated on : 2022-09-05

Solution Verified by Toppr

Correct option is D)

When we add positive integer and negative integer then it is not necessary that result would be negative integer. It can be positive integer alsoFor eg- (+8)+(−6)=2. Hence the p statement is false.

When we add two negative integers, we will always get negative integer.

For eg- (−7)+(−9)=−16. Hence q statement is also false

Was this answer helpful?

51 12

Guys, does anyone know the answer?