1

I am new to programing and I am trying to print:

money = 5000
print(f'Your account has ${ {money:,} if money > 0 else "nothing"}.')

I want it to print "Your account has $5,000." but when I run it comes back as

( {money:,} if money > 0 else "nothing")
         ^
SyntaxError: f-string: invalid syntax

yet if I do it by itself:

money = 5000
print(f'Your account has ${money:,}.')

>>>Your account has $5,000.

it works with just one pair: { }. How can I make the first one work with two pairs: { { } }?

1 Answers1

0

I will strongly suggest you to use this:

if money > 0:
    print(f'Your account has ${money:,}.')
else:
    print('Your account has nothing.')
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Divyessh
  • 2,540
  • 1
  • 7
  • 24