This is where I got stuck, trying to learn Python using web-course.
Write a program that takes a single input line of the form «number1»+
Use str.partition:
line = raw_input()
num1, _, num2 = line.partition('+')
print(int(num1) + int(num2))
If you can't use str.partition
and want to use a for
loop, then enumerate
should help:
for i, c in enumerate(line):
if c == '+':
# what goes here?
Answer
S = input()
for position in range(0, len(S)):
plus=S[position]
if (plus!="+"):
continue
number1=int(S[0:position])
number2=int(S[position+1:len(S)])
print(number1+number2)