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
5 Respostas
+ 1
Link the code that you tested. Describe what input you tried.
0
this code runs well on my machine
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
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.
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



