0

Why this code raises error?

I have ran this code on vs code, why does it show error here on sololearn? Although I have just copy-pasted the code. # Printing of diamond using * n = int(input("Enter your number: ")) m = n if n%2 != 0: for i in range(1, n+1, 2): print(f"{" " * m}{"*" *i }") m -= 1 m += 1 for i in range(n-1, 1, -2): print(f"{" " * (m+1)}{"*" * (i-1)}") m += 1 else: for i in range(1, n+1, 2): print(f"{" " * m}{"*" *i }") m -= 1 m += 1 for i in range(n-2, 1, -2): print(f"{" " * (m+1)}{"*" * (i-1)}") m += 1

23rd Nov 2025, 4:50 PM
Harsh
Harsh - avatar
5 Risposte
+ 1
Link the code that you tested. Describe what input you tried.
23rd Nov 2025, 5:52 PM
Lisa
Lisa - avatar
0
this code runs well on my machine
23rd Nov 2025, 4:56 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
0
In your f-string Make this simply change. Instead of print(f"{" " * m}{"*" *i }") Do this print(f"{' ' * m}{'*' * i}") notice the difference " " ' ' Do this for all occurrences
23rd Nov 2025, 6:36 PM
Chris Coder
Chris Coder - avatar
0
Harsh , as already mentioned, your code works here. the reason for your issue may come from the input behavior of the sololearn playground. > when running a code that require input data, a popup window appears and mentioned that we have to give all inputs in advance. > use a new line in this window for each input. > sample: to get input for: name, age, id we need 3 lines like: Paul 42 pphb1234 then press the submit button.
23rd Nov 2025, 8:15 PM
Lothar
Lothar - avatar
0
Lothar There is only one input in this code. Changing the F string as I explained fixed the console error. https://sololearn.com/compiler-playground/cBN80C1LL6sJ/?ref=app
23rd Nov 2025, 8:24 PM
Chris Coder
Chris Coder - avatar