My code almost works:
number = int(input("Please type in a number: "))
a = 2
b = 1
while a in range(number) or b in range(number):
print(a)
print(b)
a = 2
b = 2
with input 6 it works as it should:
Please type in a number: 6
2
1
4
3
6
5
but with input 5 it doesn't and show the sequence 2 1 4 3
instead 2 1 4 3 5
CodePudding user response:
This should do your job.
n = int(input())
for i in range(1, n 1, 2):
if i 1 <= n:
print(i 1)
print(i)
CodePudding user response:
you can do this with he help of the range function. Here is a simplified version:
acc = []
for i in range(1, number, 2):
acc.append(i 1)
acc.append(i)
if number % 2: # if your number is odd then add the last number manually
acc.append(number)
CodePudding user response:
It looks like you were very close the way you wrote it, but you didn't add the print function at the end so you were looking at the wrong values as output. Also, use "and" instead of "or" in this case.
number = int(input("Please type in a number: "))
a = 2
b = 1
while a in range(number) and b in range(number):
print("Original a", a)
print("Original b", b)
a = 2
print("Current a", a)
b = 2
print("Current b", b)