Please do not give homework solutions. Thanks.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Then Isaac's function does that(but you have to leave a space after
last number in the string).
def foo(x):
a, b = 0, ""
for i in x:
if i != " ":
b += i
else:
print ("this is b", b)
a += int(b)
print ("this is a",a)
You can write your own str.split or just use while loop.
12.10.2016, 15:12, "LQ Soh" :
To whom it may concern,
Can someone enlighten me as to how you can create a function such
that sum_numbers('10 5 8'), when run, will give an answer of 23, without
using str.split() and
On 12/10/16 17:58, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote:
> Sorry, I did not read the conditions that split and for should not be used.
It is even more confusing - split() may NOT be used
but 'for' MUST be used...
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.a
Sorry, I did not read the conditions that split and for should not be used.
regards,
Sarma.
On Wed, Oct 12, 2016 at 10:20 PM, D.V.N.Sarma డి.వి.ఎన్.శర్మ
wrote:
> def string_sum(s):
> total = 0
> items = s.split(" ")
> for item in items:
>total += int(item)
> p
def string_sum(s):
total = 0
items = s.split(" ")
for item in items:
total += int(item)
print(total)
You can call the function as
string_sum("10 4 5 ")
Output will be 19.
regards,
Sarma.
On Wed, Oct 12, 2016 at 3:22 PM, hell gates wrote:
>You can write y
sk again.
Thanks [😊]
From: Tutor on behalf of Bob
Gailer
Sent: Wednesday, October 12, 2016 2:26 PM
To: LQ Soh
Cc: tutor@python.org
Subject: Re: [Tutor] Adding numbers within a string
On Oct 12, 2016 4:09 AM, "LQ Soh" wrote:
>
> To whom it may
On Oct 12, 2016 4:09 AM, "LQ Soh" wrote:
>
> To whom it may concern,
> Can someone enlighten me as to how you can create a function such
> that sum_numbers('10 5 8'), when run, will give an answer of 23, without
> using str.split() and using a for loop
def sum_numbers(x):
for x in [1]:
On 12/10/16 01:37, LQ Soh wrote:
> To whom it may concern,
> Can someone enlighten me as to how you can create a function such
> that sum_numbers('10 5 8'), when run, will give an answer of 23, without
> using str.split() and using a for loop
I'm assuming this is some kind of classroom exercise?
O
To whom it may concern,
Can someone enlighten me as to how you can create a function such
that sum_numbers('10 5 8'), when run, will give an answer of 23, without
using str.split() and using a for loop
___
Tutor maillist - Tutor@python.org
To unsubscrib
10 matches
Mail list logo