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

Thursday, September 15, 2022

[FIXED] How to print consecutive numbers without spaces until reaching the user's input in python

 September 15, 2022     loops, printing, python     No comments   

Issue

I've been trying to solve this Test, but I can't print the numbers in one line using While loop, any ideas?

this is my code

if __name__ == '__main__':
n = int(input())
num = 1
while num <= n:
    print(num )
    num = num +1 

Solution

As drake14w said, you have to use the end keyword argument to avoid automatic line break.

if __name__ == '__main__':
    n = int(input())
    for i in range(1, n+1):
        print(i, end='')
    print('')


Answered By - Rodrigo Llanes
Answer Checked By - Senaida (PHPFixing Volunteer)
  • 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