Print a sequence on one line in Python 3

Viewed 11434

I've managed to get the sequencing correct, however I'm unsure how to have it print on the same line. I've got this:

n = input ("Enter the start number: ")
i = n+7

if n>-6 and n<93:
    while (i > n):
        print n
        n = n+1

and have tried this:

n = input ("Enter the start number: ")
i = n+7

if n>-6 and n<93:
    while (i > n):
        print (n, end=" ")
        n = n+1
4 Answers

this is coaded in java. the two nested loop are just to print the pattern and stop varialbe is used to terminate loop when we get the required sequence of integer.

import java.io.*;
import java.util.Scanner;

public class PartOfArray {
    
    public static void main(String args[])
    {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int stop =1;   // stop variable 
     /*nested loops to print pattern */    
    for(int i= 1 ; i <= n    ; i++)
    {
        for(int j = 1 ; j<=i ; j++)
        {
            if (stop > n){ break;} //condation when we print the required no of elements
            System.out.print(i+ " ");
            stop++;
        } 
    } 
    
    }
}
Related