Skip to main content

Posts

Showing posts with the label python

Any or All Hackerrank Solution Python | Hackerrank Python

 Any or All Hackerrank Solution Python For Explanation Watch Video :  Code: siz = int(input()) lst = list(input().split()) pos = all([int(i)>0 for i in lst]) pal = any([st == st[::-1] for st in lst]) print(pos and pal)#true 

Python Evaluation Hackerrank Solution | Hackerrank Python

 Python Evaluation Hackerrank Solution For Explanation Watch Video : Code:: # Enter your code here. Read input from STDIN. Print output to STDOUT eval(input())

Introduction to Sets Hackerrank Solution Python

 Introduction to Sets Hackerrank Solution Python code:: def  average(array):      # your code goes here     s =  set ()      for  i  in  array:         s.add(i)      return   sum (s)/ len (s) if  __name__ ==  '__main__' :     n =  int ( input ())     arr =  list ( map ( int ,  input ().split()))     result = average(arr)      print (result)

Hackerrank Write a function Solution - Python

 Hackerrank Write a function Solution - Python For Explanation Watch Video:: Code:: def  is_leap(year):     leap =  False           if  year %  400  ==  0 :         leap =  True      elif  year% 4 == 0   and  year% 100 != 0 :         leap= True      return  leap year =  int ( input ()) print (is_leap(year))

Mutations Hackerrank Solution Python

Mutations Hackerrank Solution Python  For Explanation Watch Video:: def  mutate_string(string, position, character):      return string[:position] + character + string[position+1:]  if  __name__ ==  '__main__' :     s =  input ()     i, c =  input ().split()     s_new = mutate_string(s,  int (i), c)      print (s_new)

Capitalize! Hackerrank Solution Python

 Capitalize! Hackerrank Solution Python For Explanation Watch Video:: Code: #!/bin/python3 import  math import  os import  random import  re import  sys # Complete the solve function below. def  solve(s):                                for x in s[:].split():         s = s.replace(x,x.capitalize())      return s if  __name__ ==  '__main__' :     fptr =  open (os.environ[ 'OUTPUT_PATH' ],  'w' )     s =  input ()     result = solve(s)     fptr.write(result +  '\n' )     fptr.close()

Nested Lists Hackerrank Solution Python

 Nested Lists Hackerrank Solution Python For Explanation Watch Video: Sample Input 0 5 Harry 37.21 Berry 37.21 Tina 37.2 Akriti 41 Harsh 39 Sample Output 0 Berry Harry Code: if  __name__ ==  '__main__' :     emptyDict = {}      def  add(key, value):          emptyDict[key] = value       for  _  in   range ( int ( input ())):         name =  input ()         score =  float ( input ())         add(name,score)     v = emptyDict.values()     second =  ( sorted ( list (( set (v))))[ 1 ])     second_lowest = []      for  key,value  in  emptyDic...

Find the Runner-Up Score! Hackerrank Solution Pyhton

 Find the Runner-Up Score! Hackerrank  For Explanation Watch video: Sample Input 0 5 2 3 6 6 5 Sample Output 0 5 Code: if  __name__ ==  '__main__' :     n =  int ( input ())     arr =  map ( int ,  input ().split())      print(sorted(list(set(arr)))[-2])

Text Wrap Hackerrank Solution Python

 Text Wrap Hackerrank Solution If You want Explanation Watch Video: Sample Input 0 ABCDEFGHIJKLIMNOQRSTUVWXYZ 4 Sample Output 0 ABCD EFGH IJKL IMNO QRST UVWX YZ Code: import  textwrap def  wrap(string, max_width):      return  textwrap.fill(string,max_width) if  __name__ ==  '__main__' :     string, max_width =  input (),  int ( input ())     result = wrap(string, max_width)      print (result)

Find a string Hackerrank Solution Python

 Find a string Hackerrank Solution Python For Explanation Watch Video: Sample Input ABCDCDC CDC Sample Output 2 Code: def  count_substring(string, sub_string):     c =  0     len_sub =  len (sub_string)      for  i  in   range ( len (string)- len (sub_string)+ 1 ):          if  string[i:i+len_sub]==sub_string:             c +=  1        return  c if  __name__ ==  '__main__' :     string =  input ().strip()     sub_string =  input ().strip()          count = count_substring(string, sub_string)      print (count)

What's Your Name? Hackerrank Solution python

 What's Your Name? Hackerrank Solution For Explanation Watch Video: Sample Input 0 Ross Taylor Sample Output 0 Hello Ross Taylor! You just delved into python. Code: def  print_full_name(first, last):      print ( "Hello " +first+ " " +last+ "! You just delved into python." ) if  __name__ ==  '__main__' :     first_name =  input ()     last_name =  input ()     print_full_name(first_name, last_name)

String Split and Join Hackerrank Solution Python

 String Split and Join Hackerrank Solution For Explanation Watch Video: Sample Input this is a string Sample Output this-is-a-string Code: def  split_and_join(line):      # write your code here     line = line.split( " " )     line =  "-" .join(line)      return  line if  __name__ ==  '__main__' :     line =  input ()     result = split_and_join(line)      print (result)

sWAP cASE Hackerrank Solution Python

 sWAP cASE Hackerrank Solution Python For Explanation Watch Video: Sample Input 0 HackerRank.com presents "Pythonist 2". Sample Output 0 hACKERrANK.COM PRESENTS "pYTHONIST 2". Code: def  swap_case(s):      return  s.swapcase() if  __name__ ==  '__main__' :     s =  input ()     result = swap_case(s)      print (result)

Tuples Hackerrank Solution Python

 Tuples Hackerrank Solution Python For Explanation Watch Video: Sample Input 0 2 1 2 Sample Output 0 3713081631934410656 Code: if  __name__ ==  '__main__' :     n =  int ( input ())     integer_list =  map ( int ,  input ().split())     t = ()     t =  tuple (integer_list)      print ( hash (t))          

Lists Hackerrank Solution Python

 Lists Hackerrank Solution Python For Explanation Watch Video: Sample Input 0 12 insert 0 5 insert 1 10 insert 0 6 print remove 6 append 9 append 1 sort print pop reverse print Sample Output 0 [6, 5, 10] [1, 5, 9, 10] [9, 5, 1] Code: if  __name__ ==  '__main__' :     N =  int ( input ())     L = []      for  i  in   range (N):         cmd =  input ().split()          if  cmd[ 0 ]== 'insert' :             L.insert( int (cmd[ 1 ]), int (cmd[ 2 ]))          elif  cmd[ 0 ]== 'print' :              print (L)          elif  cmd[ 0 ]== 'remove' :    ...

Finding the percentage Hackerrank Solution Python

 Finding the percentage Hackerrank Solution Python For Explanation Watch Video: Sample Input 0 3 Krishna 67 68 69 Arjun 70 98 63 Malika 52 56 60 Malika Sample Output 0 56.00 Code: if  __name__ ==  '__main__' :     n =  int ( input ())     student_marks = {}      for  _  in   range (n):         name, *line =  input ().split()         scores =  list ( map ( float , line))         student_marks[name] = scores     query_name =  input ()     arr = student_marks[query_name]  #25 26.5 28      sum  =  0      for  i  in  arr:          sum ...