#๐Ÿ”’ Code only works halfway?

47 messages ยท Page 1 of 1 (latest)

scarlet groveBOT
#

Hey @slate breach!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
#

@slate breach

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

chrome valve
#

what is a by the time the next while loop starts?

wintry summit
#

"when in doubt, print more out"

#

(until it becomes too much, at which point use a debugger :p)

chrome valve
# slate breach ?

what is the value of the variable a when the second while loop, the one that prints, is reached?

slate breach
chrome valve
#

if you don't assign it as such, no

you assign a to 0 once, then assign it to progressively higher numbers in the loop, and then the next loop starts

#

you might be thinking of for-loops, where the variable is set before entering the loop body

slate breach
chrome valve
#

what part of the explanation failed to reach you? give me something, here

fast trellis
#

the first while loop is fine

#

the second loop is wrong

#
numbers = []
a = 0

while a < 10:
    n = int(input('n:'))
    numbers.append(n)
    a += 1

numbers.sort(reverse=True)

i = 0
while i < len(numbers):
    print("Number "+str(i+1)+": "+str(numbers[i]))
    i += 1```
fast trellis
#

the error in your code was that you use a for both loops

#

in my code i just created a new variable 'i' to handle the while loop

#

if you need help understanding the code

#

feel free to ask

slate breach
fast trellis
#

yes?

slate breach
#

how can turn the simple n into a

n2:
n3:
   ...
fast trellis
#

sorry not quite sure what you mean

#

you want to turn n into a?

slate breach
#

how can i do the same with the input

regal quail
#

So, you want to input only one number (n), then print (n) numbers, or you want to input (n) numbers?

slate breach
#

i just want the the (n:) input which is asked 10 times to be accompanied with its corresponding number

#

for example the 3rd number should be asked like "n3:"

#

and so on

regal quail
#

Try

a = 1
while True: # loop forever
  input('n' + a + ':')
  a += 1
#

My bad. I just updated my code

slate breach
#

right?

regal quail
#

You might want this instead:

while a < 10:
  n = int(input('n' + a + ':'))
  a += 1
slate breach
#

oh alright

slate breach
regal quail
#

Ah, my bad.
It should be str(a) instead of just a

#

In the print thing only

slate breach
regal quail
#

๐Ÿ‘

slate breach
#

!close

scarlet groveBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.