Python Conditional Remaining Operator Questions

Asked 2 years ago, Updated 2 years ago, 20 views

print('+ and -) alternately.')
n = int(input()' How many should I print?: '))

for i in range(n):
    if i % 2:
        print('-', end='')
    else:
        print('+', end='')

print()

If you look at it

if i % 2:

I don't understand this part. If == 0 is omitted, ' -' should be printed first, but ' +' should be printed first. I'd appreciate it if you could tell me how it's printed

python

2022-09-20 15:16

1 Answers

If a numeric variable appears in the conditional expression,

True if any value exists,

If there is no value, (0) False.


2022-09-20 15:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.