如何在python中打印以下模式

时间:2021-03-04 05:41:03

标签: python

 public static void main (String[] args){
        
   int[] getArray; //reference to an int array of type and takes no parameters 
  
    System.out.println("How many numbers would you like to enter?" ); 
    int size = scan.nextInt(); 
    int[] nums; //reference to nums array of type int  
    nums = new int[size]; /* new array of type int. assigned to nums. 
    size, to specify number of elements array will have */
  
  for(int i=0; i<nums.length; i++){
    System.out.println("Enter a number." +(i+1)+ "left"); 
    nums[i] = scan.nextInt(); //storing user input into array
  
    return nums;
  
  }//closing for loop
  
    int[] minimumValue; 
    min = scan.nextInt();
    min = nums[0]; //assigning min value to first element in array
    
    return min; 
    
  for(int i=0; i<min.length; i++){
  
    if(i<min){
      min = nums[0];
    }
  }
   return min;
  
  public static void printArray (int[] getArray){ //method to print out array
    for(int i = 0; i < nums.length; i++){ 
    System.out.print(nums.length); //print out array
    }
  }
  
  public static void printArrayInReverse(int[] getArray){  //method for arrayInReverse
    for(int i = nums.length - 1; i >= 0; i--){ 
    System.out.print(nums[i]); 

    }
  }
  
  int[] numbers = getArray();// calling getArray method
  
  public static void main (String[] args){
    System.out.print("************");
    printArray(numbers); //calling printArray method and passing numbers through it

    printArrayInReverse(numbers);// calling printArrayInReverse method and passing numbers through it

    System.out.print(minimumValue(numbers)); /* calling minVal through print statement and passing 
                                              numbers through it*/
  } 
  
  }
  }

我已经尝试了很长时间,但未能为其编写代码。 请分享上述模式的代码,因为我正在努力弄清楚。

4 个答案:

答案 0 :(得分:2)

print('''1
2 6
3 7 10
4 8 11 13
5 9 12 14 15''')

答案 1 :(得分:2)

试试:

l = [0, 4, 7, 9, 10]
for i in range(5):
     print(' '.join([str(i+1+l[e]) for e in range(i+1)]))

答案 2 :(得分:0)

这应该适合你:

for y in range(0,6): #height of right angled triangle
    z = y
    for x in range(0,y):
        if x ==0:
            print(z,end = ' ')
        else:
            z = z + (10 - (5+x)) #if you notice pattern its n n+4 n+3 n+2 .... so just implementing that
            print(z,end = ' ')
    print('\n')

答案 3 :(得分:0)

逻辑

    for(i=1;i<=n;++i){
    int k=i,m=0;
    for(j=1;j<=i;++j)
    {
        k=k-m;
        print(k);   
        k=k+5;
        m++;
    }   
    print("\n");
}
<块引用>

这是逻辑,将其转换为python等效语法。