#๐ Help right quick
21 messages ยท Page 1 of 1 (latest)
@short thorn
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.
you mean the color?
No referring to the formatting of the diamond shape compare to my output
!e
# Function to create diamond
def diamond(size):
# Make sure size is odd
if size % 2 == 0:
size += 1
print(f"Size must be an odd number; we will increase it to 9")
# FOR loop for the top half of diamond
for i in range(size // 2 + 1):
for j in range(size // 2 - i):
print("", end="")
# Print the increase number from 0 to 9
for j in range(2 * i + 1):
print(j % 10, end="")
print()
# FOR loop the bottom half
for i in range(size // 2 - 1, -1, -1):
for j in range(size // 2 - i):
print("", end="")
# Print increasing numbers 0 to 9 on bottom half
for j in range(2 * i + 1):
print(j % 10, end="")
print()
# define the main function and get input to generate the diamond
def main():
size = 3
diamond(size)
main()
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 0
002 | 012
003 | 0
I don't see you adding any spaces to the left side
@grave drift @spring basin
def diamond(size):
# Make sure size is odd
if size % 2 == 0:
size += 1
print(f"Size must be an odd number; we will increase it to 9")
# FOR loop for the top half of diamond
for i in range(size // 2 + 1):
for j in range(size // 2 - i):
print("", end=" ")
# Print the increase number from 0 to 9
for j in range(2 * i + 1):
print(j % 10, end="")
print()
# FOR loop the bottom half
for i in range(size // 2 - 1, -1, -1):
for j in range(size // 2 - i):
print("", end=" ")
# Print increasing numbers 0 to 9 on bottom half
for j in range(2 * i + 1):
print(j % 10, end="")
print()
# define the main function and get input to generate the diamond
def main():
size = int(input("Enter an odd number for the size of the diamond: "))
diamond(size)
main()```
Added the spaces, I also dont know why my numbers isn't exactly in order anything you spot?
Hey @short thorn!
Add a py after the three backticks.
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
!e
# Function to create diamond
def diamond(size):
# Make sure size is odd
if size % 2 == 0:
size += 1
print(f"Size must be an odd number; we will increase it to 9")
# FOR loop for the top half of diamond
for i in range(size // 2 + 1):
for j in range(size // 2 - i):
print("", end=" ")
# Print the increase number from 0 to 9
for j in range(2 * i + 1):
print(j % 10, end="")
print()
# FOR loop the bottom half
for i in range(size // 2 - 1, -1, -1):
for j in range(size // 2 - i):
print("", end=" ")
# Print increasing numbers 0 to 9 on bottom half
for j in range(2 * i + 1):
print(j % 10, end="")
print()
# define the main function and get input to generate the diamond
def main():
size = 5
diamond(size)
main()
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 0
002 | 012
003 | 01234
004 | 012
005 | 0
what order are you expecting them to be in?
all these range calls you're using are generating 0 through stop-1
you could have a counter variable and just increment it in every loop and use that as the number you write out, or do the math for your range calls to properly generate the numbers you need
How do I do that
c = 0
...
for j in range(2 * i + 1):
print(c % 10, end="")
c += 1
same for all times you print j in the loop
This help channel has been closed. 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.