Posts

Showing posts from November, 2020

Right Arrow Pattern

Write a program to print the Right Arrow Pattern. Input Format: Take an input Integer which is from stdin. Output Format: print Right Arrow pattern Example Input: 5 Output: ***** **** *** ** * ** *** **** ***** SOLUTION: n=int(input()) for i in range(n):     for j in range(2*i):      #for spaces as each i th row has 2*i spaces         print(" ",end="")     for k in range(n-i):     #for stars as each i th row has n-i stars         print("*",end="")          print("")                     # half pattern is completed here for i in range(2,n+1):     #range started from 2 as the single star at middle is already                                         ...

Position Of A Man

  A man from origin can move in below direction, 10 Mts right in first turn, 20 Mts up in second turn, 30 Mts left in third turn, 40 Mts down in fourth turn, 50 Mts right in fifth turn, 10 Mts right in sixth turn, 20 Mts up in seventh turn, 30 Mts left in eighth turn, 40 Mts down in ninth turn, 50 Mts right in tenth turn and so on Write a program to print the position of man from origin in nth turn. where 2<=n <= 1000. n = no of turns. Input Format: Take integer from stdin. Output Format: print the position of man from origin. Example Input: 3 Output: -20 20 Explanation In each turn the step size increases by 10. Also, the turns move from right, up, left, down and right then the same steps keeps repeating In our case, man starts from (0,0) --> (10,0) --> (10,20) --> (-20,20) Hence answer is (-20,20) SOLUTION: n=int(input()) x=0 y=0 i=1 while i<=n:     t=i%5         #since after 5 turns for 6th turn we have to start like 1st turn ...

X Pattern

  Write a program to take String if the length of String is odd print X pattern otherwise print INVALID. Input Format: Take a String as input from stdin. Output Format: print the desired Pattern or INVALID. Example Input: edyst Output: e t d s y d s e t SOLUTION: s=input() l=len(s) if(l%2 != 0): for i in range(0,l): j=l-i-1 for k in range(0,l): if(k==i or k==j): print(s[k],end="") else: print(end=" ") print("") else: print("INVALID")

FIBONACCI SERIES

  In Fibonacci series, the next number is the sum of previous two numbers. The series starts with   0   and   1 , and then the next numbers are a sum of the previous 2 numbers. For example 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc. Here the first 2 numbers are  0  and  1 The next numbers are: 1 (= 1 + 0) 2 (= 1 + 1) 3 (= 2 + 1) 5 (= 3 + 2) And so on… Write a program the first  n  numbers of the Fibonacci series. Hint: You already know the first 2 values. How can you calculate the remaining? Input Format The first line contains  T  the number of test cases. The following  T  lines contain  n , the input for the Fibonacci Series. Output Format Print the values on a single line, separated by a space character. At the end of the line, print a new line. Sample Input / Output Input 5 3 4 8 9 7 Output 0 1 1 0 1 1 2 0 1 1 2 3 5 8 13 0 1 1 2 3 5 8 13 21 0 1 1 2 3 5 8 SOLUTION:             ...