Python 1-2+3-4....99=? Here's the question, I see other people's writing, a variety of, oneself also write a

Source: Internet
Author: User

f = ""
s = ""
i = 1
sum = 0
While I < 100:
if I%2 = = 1 and i < 99:
f = "-"
sum = sum + I
elif i = = 99:
f = "="
sum = sum + I
elif I%2 = = 0:
F = "+"
sum = sum-i
s = s + str (i) + F
i + = 1
Print (S,sum)

#同时我也看到有人这样写的, inspired ...

s = ""
Start = 1
sum = 0
While start < 100:
temp = start% 2
If temp ==1:
If start ==1:
s = str (start)
Else
s = s + "+" + str (START)
sum = sum + start
Else
s = s + "-" +str (start)
sum = Sum-start
Start + = 1
Print (s)
Print (sum)

#我发现人的想象力真是无穷的, although the problem is complicated to think, but also a good solution to the problem is the last equal sign is not printed

Python 1-2+3-4....99=? Here's the question, I see other people's writing, a variety of, oneself also write a

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.