PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 14, 2022

[FIXED] how to replace the last + with =?

 August 14, 2022     output, string     No comments   

Issue

total = 0
number = 1
until = int(input("Until: "))

while total < until:
    print(number, end = " + ")
    total += number
    number += 1

print(total)

Solution

You have to add a condition to check whether you have reached the end of loop and then print '=' in that case. Something like this.

total = 0

number = 1

until = int(input("Until: "))

while total < until:
    total += number

    if total >= until:
        print(number, end=" = ")
    else:
        print(number, end = " + ")

    number += 1
print(total)


Answered By - Daniyal Ishfaq
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing