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
If a numeric variable appears in the conditional expression,
True if any value exists,
If there is no value, (0) False.
© 2024 OneMinuteCode. All rights reserved.