Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can i write a cod with Walrus

Write a program that calculates the sum of the numbers entered by the user. The program will continue until the user has not entered an empty string. (use the walrus operator in the condition).

I think all my code is wrong
summ = []
while (b := int(input('x: '))) != '':
    summ.append(b)

print(sum(summ))

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You could use an assignment expression (a.k.a. walrus operator) for your use-case like this:

summ = 0

while (b := input('x: ')):
  summ += int(b)

print(summ)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading