Posts

String Membership in Python

String Membership You just need to take string and a character as an input from stdin and print 'True' if that character is present in that string otherwise print 'False'. Input Format You will be taking a string and a character as an input from stdin. Constraints 1 <= |S| <= 10000 Output Format Print 'True' if that character is present in that string otherwise print 'False'. Sample TestCase 1 Input Hello Techgig H Output True Solution: import sys def main(): # Write code here ip1=raw_input() ip2=raw_input() length=len(ip1) for i in range(0,length): if(ip2==ip1[i]): sys.stdout.write("True") break else: sys.stdout.write("False") break main()

String Repetition in Python

String Repetition You just need to take a string and a integer as an input from stdin and repeat the string up to the count given as in integer. Input Format You will be taking a string and an integer as an input from stdin. Constraints 1 <= |S| <= 1000 1 <= N <= 100 Output Format You need to print the string to the stdout. Sample TestCase 1 Input Hello 2 Output HelloHello Solution import sys def main(): # Write code here ip1=raw_input() val=input() for i in range(0,val): sys.stdout.write(ip1) main()

String Concatenation in Python

String Concatenation You just need to take two strings as input from stdin and concatenate them and print the concatenated string to the stdout. Input Format You will be taking two strings as an input from stdin one on each line respectively. Constraints 1 <= |S| <= 10000 Output Format You need to print the concatenated string to the stdout. Sample TestCase 1 Input Hello Techgig Output HelloTechgig Solution import sys def main(): # Write code here ip1=raw_input() ip2=raw_input() sys.stdout.write(str(ip1).strip(" ")+str(ip2).strip(" ")) main()

Print Exact Slice Of String in Python

Print Exact Slice Of String You need to take string input and two other numbers which will be the start and end point of the slice and you need to print that slice of string to the stdout. Input Format You will be taking a string as an input from stdin and two integers one on each line. Constraints 1 <= |S| <= 10000 Output Format You need to print the slice of the string to the stdout. Sample TestCase 1 Input Hello Techgig 1 4 Output ello import sys def main(): # Write code here word=raw_input() one=input() two=input() obj=slice(one,two+1) sys.stdout.write(str(word[obj])) main()

Power of a Number in Python

Python.math module provides access to the mathematical functions defined by the C standard. One of the widely used function is math.pow(x, y) which Returns x raised to the power y. Now, you are given three integers x, y and M. You have to print ( x ^ y ) Mod M. Input format First line will contain three integers x, y, and M. Constraints 1 <= X <= 20 1 <= Y <= 100 2 <= M <= 100 Output Format Print an Integer denoting answer of the calculation (x ^ y ) Mod M. Sample TestCase 1 Input 10 2 3 output 1 Explanation 10^2 = 100 100%3=1 Solution : import sys import math def main(): # Write code here ip=raw_input() ip=map(int,ip.split(' ')) x=int(ip[0]) y=int(ip[1]) m=int(ip[2]) o1=math.pow(x,y) o2=o1%m sys.stdout.write(str(int(o2))) main()

Find Angle in Python

Image
Given a right angled triangle ABC, right angled at B. Find angle ABD, where D is the mid-point of the hypotenuse(side AC). You will be given two integers denoting sides AB and BC respectively. Round off your answer to the nearest Integer. Input Format First line will contain an Integer denoting side AB. Second line will contain an Integer denoting side BC. Constraints 1 <= side AB <= 200 1 <= side BC <= 200 output Output Angle ABD, rounded off to nearest integer. Sample TestCase 1 Input case 6 6 output 45 Solution: import sys import math def main(): # Write code here adjacent=input() opposite=input() #since tan=opposite/adjacent tangent=opposite/adjacent sys.stdout.write(str(int(math.degrees(math.atan(tangent))))) main()

Fibonacci series in Python

''' Read input from STDIN. Print your output to STDOUT ''' #Use input() to read input from STDIN and use print to write your output to STDOUT import sys def main(): # Write code here val=input() x=0 y=1 z=x+y sys.stdout.write(str(x)+" "+str(y)) for i in range(val-2): z=x+y x=y y=z sys.stdout.write(" "+str(z)) main()