#// palindrone with out using reverse logic #n="madam" #i=0 #j=len(n)-1 #print(i) #print(j) #while i<j: # if n[i]!=n[j]: # print("it is not a palendrone") # break #i=i+1 len(n),1): #j=j-1 #else: # print("it is a palindrone") #//********************************non repeating char. #n="madam" #lst=[] #for items in n: # lst.append(items) #print(lst) #for i in range(0,len(n),1): # count=1 #if lst[i]!=-1: # for j in range(i+1,len(n),1): # if lst[i]==lst[j]: # count=count+1 # lst[j]=-1 #if count==1: # print(lst[i]) # break #max no.of count: #s="wel to python class" #l=s.split() #max=len(s) #print(l) #for ele in l: #print(len(ele)) # if len(ele)<max: # max=len(ele) # res=ele #print(res) #/// DICTONARY /// #d={ # "brand": "Royalenfield", #"model": "classic350", #"year": "2016", #} #d["year"] = 2018 #for x in d.keys(): # print(x) #for y in d.values(): # print(y) #for z in d.items(): # print(z) #for t1,t2 in d.items(): # print(t1,t1) #d={ # "brand": "RoyalEnfirld", # "model": "classic350", # "year": 2016 #} #for x in d: # print(x,"values is",d[x]) #x=['key1','key2','key3'] #y={1},{2},{3} #d=dict.fromkeys(x,y) #print(d['key2']) # with out using doctonary /// '''d={ "brand": "Royalenfield", "modal": "classic350", "year": 2016 } print(d["model"]) print(d.get("model1",0)) s="madam" d={} for i in s: d[i]=d.get(i,0)+1 sum=0 for j in d.values(): sum=sum+j print(sum) s="sruthiradhika" d={} for i in s: if i in "aeiouAEIOU": d[i]=d.get(i,0)+1 print(i) print(d) sum=0 for j in d.values(): sum=sum+j print(sum)''' '''s1=input() s2=input() print(sorted(s1)) print(sorted(s2)) if sorted(s1)==sorted(s2): print("anagram") else: print("not a anagram")''' '''s="welcome to python class" l=s.split() print(l) for i in l: print(i[::-1],end=" ") s="welcome to python class" l=s.split() print(l) for i in range(0,len(l),2): print(l[i][::-1],end=" ")''' '''l=[7,2,4,6] print(sorted(l)) print(sorted(l)[::-1])''' ''' lamda functions ''''' '''def add(x,y): print(x+y) add(4,6) def sub(x,y): return x-y print(sub(4,6))''' '''x=lambda x,y:x+y x(4,6) seq1=[1,2,3,4,5] def times4(var): return var*4 print(list(map(times4,seq1))) print(map(times4,seq1))''' '''lambda expresion seq1=[1,2,3,4,5] print(map(lambda var:var*4,seq1)) print(list(map(lambda var:var*4,seq1))) ''' '''seq1=[1,2,3,4,5] print(list(map(lambda item:item%2==0,seq1))) print(list(filter(lambda item:item%2==0,seq1)))''' '''for row in range(0,4,1): for col in range(0,4,1): print("*",end=" ") print()''' '''for row in range(0,4,1): for col in range(0,row+1,1): print("*",end=" ") print()''' '''for row in range(0,4,1): for col in range(0,4,1): print("ABCD",end=" ") print() k=1 for row in range(0,4,1): for col in range(0,k,1): print("**",end=" ") k=k-1 print()''' '''for row in range(0,4,1): print("* "*4)''' '''for i in range(4,0,-1): print("* "*(i+1))''' '''for i in range(4,0,-1): print("* "*(i+1)) i=4 while i>0: print("*"*i) i=i-1''' #condition for apply '''for i in range(0,4,1): print(" "*3,"*"*1) print(" "*2,"*"*2) print(" "*1,"*"*1) print(" "*0,"*"*4)''' '''for i in range(0,4,1): print(" "*(4-(i-1)),"*"*(i+1))''' '''for i in range(0,4,1): print(" "*(4-i-1) ,"* "*(i+1))''' '''for i in range(0,8,1): print(" "*(i+1) ,"* "*(8-i-1))''' '''for i in range(0,4,1): print(" "*(i+1),"* "*(4-i)) for i in range(1,4,1): print(" "*(5-i-1),"* "*(i+1))''' '''for row in range(0,6,1): for col in range(0,7,1): if ((row==0 and col%3!=0)or(row==1 and col%3==0)or(row==2 and col%3==0)or(row-col==2)or(row+col==8)): print("S",end=" ") else: print(" ",end=" ") print()''' '''for row in range(0,7,1): for col in range(0,15,1): if((col==0 and row>0 and row<5)or(col==4 and row>0 and row<5)or(row==0 and col<4)or(row==5 and col>4 and col<5)or(row>5)or(col-row==11)): print("q",end=" ") else: print(" ",end=" ") print()''' #Trapezium Pattern '''n=int(input()) a=1 b=n*n+1 for i in range(n,0,-1): for h in range(n-i): print("--",end="") for j in range(i): print(a,end="*") a+=1 for k in range(i-1): print(b,end="*") b+=1 print(b) b=b-2*(i-1)''' #ARRAY '''from array import * r=array("f",[3,5,7,8]) print(r[0])''' '''for i in range(1,8,1): print("*"*i) [print("*"*i) for i in range(1,6,1)]''' '''from array import * r=array("i",[3,5,7,8]) a=list(r) a.append(2.5) print(a)''' '''from array import * r=array("I",[3,5,7,8]) for i in range(len(r)): print(r[i])''' '''from array import * r=array("i",[3,5,7,8]) lst=[] for i in r: lst.append(i) lst.append(2.5) print(lst)''' '''from array import * a=array("i",[3,5,7,8]) b=array(a.typecode,[i for i in a]) print(b)''' '''from array import * r=array("i",[3,5,7,8]) for i in range(len(r)-1,-1,-1): print(r[i])''' '''from array import * a=array("i",[3,5,7,8]) b=array(a.typecode,[i for i in a[::-1]]) print(b)''' '''from array import * a=array("i",[3,5,7,8]) d={} for i in range(len(a)): d["i"+(i+1)]=a[0]''' #convert arr to dict '''from array import * a=array("i",[3,5,7,8]) d={} for i in range(len(a)): d["i"+(i+1)]=a[0] m=[[1,2,3], [4,5,6], [7,8,8]] print(m[0]) print(m[1]) print(m[2]) m=[[1,2,3],//using range function [4,5,6], [7,8,8]] for i in range(0,len(m),1): print(m[i]) m=[[1,2,3], [4,5,6], [7,8,8]] for i in m: print(i) #positive indexing m=[[1,2,3], [4,5,6], [7,8,8]] print(m[1][1])''' #negative indexing '''m=[[1,2,3], [4,5,6], [7,8,8]] print(m[-2][-2]) m=[[1,2,3], [4,5,6], [7,8,8]] m[2][2]=9 for i in m: print(i) m=[[1,2,3], [4,5,6], [7,8,8]] m[0][2]=4 m[1][2]=8 m[2][2]=12 for i in m: print(i)''' '''m=[[1,2,3], [4,5,6], [7,8,8]] k=0 for i in range(0,len(m),1): k=k+4 m[i][len(m)-1]=k for i in m: print(i)''' '''m=[[1,2,3], [4,5,6], [7,8,8]] for i in range(0,len(m),1): m[i][len(m)-1]=4*(i+1) for i in m: print(i)''' '''row=int(input("row")) col=int(input("col")) m=[] print("enter the elements") for r in range(0,row,1): l=[] for c in range(0,col,1): l.append(int(input())) m.append(l) for i in m: print(i)''' '''x=[[1,2,3], [4,5,6], [7,8,8]] y=[[4,2,3], [4,7,6], [7,8,8]] sum=[[0,0,0], [0,0,0], [0,0,0]] for r in range(0,len(x),1): for c in range(0,len(x[0]),1): sum[r][c]=x[r][c]+y[r][c] print(sum)''' '''x=[[1,2,3], [4,5,6], [7,8,8]] y=[[4,2,3], [4,5,6], [7,8,8]] r=[[0,0,0],[0,0,0],[0,0,0]] for row in range(0,len(x),1): for col in range(0,len(x[0]),1): r[row][col]=x[row][col]-y[row][col] for i in r: print(i)''' '''x=[[1,2,3], [4,5,6], [7,8,8]] y=[[4,2,3], [4,7,6], [7,8,8]] print([[x[row][col]*y[ow][col]]for c in range(0,len(x),1)])''' '''x=[[1,2,3], [4,5,6], [7,8,8]] print(x[0][0]+x[0][1]+x[0][2]) print(x[1][0]+x[1][1]+x[1][2]) print(x[2][0]+x[2][1]+x[2][2]) for row in range(0,len(x),1): sum=0 for col in range(0,len(x[0]),1): sum=sum+x[row][col] print(sum)''' #create a list '''x=[[1,2,3], [4,5,6], [7,8,8]] print(x[0][0]+x[0][1]+x[0][2]) print(x[1][0]+x[1][1]+x[1][2]) print(x[2][0]+x[2][1]+x[2][2]) # add m=[] m=[] for row in range(0,len(x),1): sum=0 l=[] for col in range(0,len(x[0]),1): sum=sum+x[row][col] l.append(sum) m.append(l) print(l)''' #maltiplication of matrics '''x=[[1,2,3], [4,5,6], [7,8,8]] y=[[4,2,3], [4,7,6], [7,8,8]] r=[[0,0,0],[0,0,0],[0,0,0]] for r1 in range(0,len(x[0]),1): for c in range(0,len(x[0]),1): r[r1][c]=x[r1][c]*y[c][r1] print(r)''' #matiplication with output list '''x=[[1,2,3], [4,5,6], [7,8,8]] y=[[4,2,3], [4,7,6], [7,8,8]] r=[[0,0,0],[0,0,0],[0,0,0]] for r1 in range(0,len(x[0]),1): for c in range(0,len(x[0]),1): r[r1][c]=x[r1][c]*y[c][r1] m1=[] for i in range(0,len(r[0]),1): sum=0 l=[] for j in range(0,len(r[0]),1): sum=sum+r[i][j] l.append(sum) m1.append(l) print(m1)''' # '''x=[[1,2,3], [4,5,6], [7,8,8]] y=[[4,2,3], [4,7,6], [7,8,8]] s=[[0,0,0],[0,0,0],[0,0,0]] for row in range(0,len(x[0]),1): for col in range(0,len(x[0]),1): for k in range(0,len(x),1): s[row][col]=s[row][col]+(x[row][k]*y[k][col]) print(s)''' #student details '''import math a=str(input()) b=int(input()) c=float(input()) e=math.floor(c*100)/100 d=str(input()) print("Name:",a) print("Age:",b) print("CGPA:",e) print("Grade:",d) # length =int(input()) breadth = int(input()) perimeter = 2 * (length + breadth) area = length * breadth print("the required length is",perimeter, "m") print("the required area of carpet is ",area, "sqm") ''' '''input_a=input() if input_a.isalpha(): if a in("a,e,i,o,u,A,E,I,O,U"): print("Vowel") else: print("consonat")''' #scholorship '''age=int(input()) year=int(input()) income=int(input()) arrear=int(input()) score=float(input()) attendance=float(input()) if(age>=18 and age<21)and(year>=2021)and(score>=60.0)and(attendance>=80.0): if(arrear<=2)and(income<=200000): print("Eligible") elif(arrear>2)and(income<200000): if(score>=80.0)and(attendance>=90): print("Partially Eligible") else: print("Not Eligible") elif(arrear>2)and(200000<income<250000): if(score>=80.0)and(attendance>=90.0): print("Partially Eligible") else: print("Not Eligible") elif(arrear<=2)and(200000<income<250000): if(score>=80.0)and(attendance>=90.0): print("Partially Eligible") else: print("Not Eligible") else: print("Not Eligible")''' # debt repay '''p=float(input()) r=float(input()) n=float(input()) si=(p*n*r)/100 a=si+p d=si*0.02 f=a-d print("%.2f"%si) print("%.2f"%a) print("%.2f"%d) print("%.2f"%f)''' # number of days '''year=int(input()) month=int(input()) if month==2: if(year%4==0 and year%100!=0)or year%400==0: days=29 else: days=28 elif month==4 or month==6 or month==9 or month==11: days=30 else: days=31 print(str(days)+"days")''' #cirket '''total_balls=int(input()) total_runs=int(input()) runs_scored=int(input()) balls_bowled=int(input()) overs=total_balls//6 over_done=balls_bowled//6+(balls_bowled%6)*0.1 crr=runs_scored/overs_done trr=total_runs/overs print(overs) print("%.1f"%overs_done) print("%.1f"%crr) print(".1f"%trr) if crr>=trr: print("Eligible to Win") else: print("Not Eligible to Win")''' #TREAR FINDER '''a=int(input()) b=int(input()) c=int(input()) lst=[a,b,c] l=sorted(lst)[len(lst)-2] print("The treasure is in the box which has the number",l) min_num=min(a,b,c) for i in range(min_num,0,-1): if a%i==0 and b%i==0: hcf=i break print("The code to open the box is"+str(hcf))''' #collatz control statements '''n=int(input()) count=0 print(n) while n!=1: if n%2==0: n=n//2 count+=1 else: n=(3*n)+1 count+=1 print(n) print(count)''' #STRONG NUMBER '''num=int(input()) temp=num sum=0 def fact(n): fact1=1 for i in range(1,n+1): fact1=fact1*i return fact1 while num>0: R=num%10 x=fact(R) sum=sum+x num=num//10 if sum==temp: print("Yes") else: print("No")''' #RIGHT ANGLE TRIANGLE '''rows=int(input()) for i in range(rows,0,-1): for j in range(1,i+1): print("*",end="") print(" ")''' # SUM OF DIGIT SINGLE DIGIT '''n1=int(input()) def rep(num): sum=0 while num>0: R=num%10 sum=sum+R num=num//10 return sum s=rep(n1) if s>9: rep(s) print(rep(s))''' #SPECIAL NUMBERS '''m=int(input()) n=int(input()) for i in range(m,n+1): if i<=99: sum=i%10+i//10 prod=(i%10)*(i//10) if sum+prod==i: print(i)''' #Amoeba Multiplication '''num=int(input()) a=0 b=1 for i in range(1,num): c=a+b a=b b=c print(a,end=" ")''' #asci value '''a=str(input()) print(ord(a))''' # NEWS PEAPAR '''a=int(input()) b=int(input()) c=int(input()) p=(a*b)-(a*c)-100 print(p)''' #kaprekar number '''n=int(input()) count=0 temp=n sq=n*n while n>0: r=n%10 n//=10 count+=1 p=10**count q=sq//p rem=sq%p sum=q+rem if sum==temp: print("Kaprekar Number") else: print("Not a Kaprekar Number")''' # print to 10001 numbers '''def kar(n): count=0 temp=n sq=n*n while n>0: r=n%10 n//=10 count+=1 p=10**count q=sq//p rem=sq%p sum=q+rem if sum==temp: print(sum,end=" ") for i in range(1,10001,1): kar(i)''' #Arrays 1D - Same or Not '''n1=int(input()) n2=int(input()) s1=0 s2=0 for i in range(n1): h=int(input()) s1+=h for i in range(n2): h=int(input()) s2+=h if s1==s2: print("Same") else: print("Not Same")''' #Input & Output - ASCII Values - II '''a=int(input()) print(chr(a))''' #Arrays 1D - Count distinct elements '''n=int(input()) arr=[int(input()) for i in range(n)] distinct_elements=[] for i in range(n): if arr[i] not in distinct_elements: distinct_elements.append(arr[i]) print("There are", len(distinct_elements), "distinct element in the array.")''' #Input & Output - Round Off '''from math import* a=float(input()) print(int(a)) print(ceil(a)) print(floor(a))''' # same or not (method 2) '''n1=int(input()) n2=int(input()) lst1=[int(input()) for i in range(0,n1,1)] lst2=[int(input()) for j in range(0,n2,1)] s1=0 s2=0 for i in lst1: s1=s1+i for j in lst2: s2=s2+j if n1==n2 and s1==s2: print("Same") else: print("Not Same")''' #Arrays 1D - Compatible array '''n1=int(input()) lst1=[int(input()) for i in range(0,n1,1)] n2=int(input()) lst2=[int(input()) for j in range(0,n2,1)] if n1!=n2: print("Incompatible") else: for j in range(0,n1,1): if lst1[j]<lst2[j]: print("Incompatible") break else: print("Compatible")''' #Arrays 1D - Sum of even numbers and odd numbers '''n=int(input()) arr=[int(input()) for i in range(0,n,1)] even_sum=0 odd_sum=0 for i in range(n): if arr[i]%2==0: even_sum=even_sum+arr[i] else: odd_sum=odd_sum+arr[i] print("The sum of the even numbers in the array is",even_sum) print("The sum of the odd numbers in the array is",odd_sum)''' #Arrays 1D - Ascending order '''n=int(input()) lst=[int(input()) for i in range(0,n,1)] lst.sort() print("The Sorted array is:") for i in lst: print(i)''' #Arrays 1D - Queue '''n,m=map(int,input().split()) a=list(map(int,input().split())) bus=0 sum=0 for i in range(n): if sum+a[i]>m: bus=bus+1 um=a[i] else: sum=sum+a[i] if sum>0: bus=bus+1''' #Arrays 1D - Array insertion '''n=int(input()) arr=[int(input()) for i in range(n)] pos=int(input()) if pos>n: print("Invalid Input") else: ele=int(input()) print("Array after insertion is") for i in range(n): if i==pos-1: print(ele) print(arr[i])''' #Arrays 1D - Remove duplicate elements '''n=int(input()) arr1=[int(input()) for i in range(n)] distinct_elements=[] for i in range(n): if arr1[i] not in distinct_elements: distinct_elements.append(arr1[i]) for i in distinct_elements: print(i) #Arrays 1D - Remove duplicate elements(method-2) n=int(input()) a=[int(input()) for i in range(0,n,1)] for i in range(n): flag=0 for j in range(i,-1,-1): if a[i]==a[j]: flag+=1 if flag==1: print(a[i])''' #Arrays 2D - Transpose Matrix '''r=int(input()) a=[] for i in range(r): row=list(map(int,input().split())) a.append(row) for row in a: print(*row) print("Transpose matrix is:") for i in range(r): for j in range(r): print(a[j][i],end=" ") print()''' #Strings - Reverse each word of a string '''str = input() len = len(str) i = j = startIndex = 0 #input Hello World# endIndex = len - 1 for i in range(len - 1, -1, -1): if str[i] == ' ' or i == 0: if i == 0: startIndex = 0 else: startIndex = i + 1 for j in range(startIndex, endIndex + 1): print(str[j], end='') endIndex = i - 1 print(" ", end='')''' #Strings - String Subsequence '''t = input() s = input() if len(s) > len(t): print("0") #inputabcde abe i = j = 0 while j < len(t): if i < len(s) and s[i] == t[j]: i += 1 j += 1 else: j += 1 if i == len(s): print("1") else: print("0")''' #Strings - String Anagram #inputeat #ate # '''s1 = input() s2 = input() len1 = len(s1) len2 = len(s2) found = 0 notFound = 0 if len1 == len2: for i in range(len1): found = 0 for j in range(len2): if s1[i] == s2[j]: found = 1 break if found == 0: notFound = 1 break if notFound == 1: print("Not Anagram") else: print("Anagram") else: print("Not Anagram")''' #Recursion - Fibonacci Series #input 5 '''def fib(n): if n == 1: return 0 if n == 2: return 1 return fib(n - 1) + fib(n - 2) n = int(input()) print("The term " + str(n) + " in the Fibonacci series is " + str(fib(n)))''' #Recursion - Compute a^n input is 2,4 '''def power(a, n): if n == 0: return 1 elif n == 1: return a elif n % 2 == 1: return a * power(a, n - 1) else: return power(a * a, n // 2) a = int(input()) n = int(input()) res = power(a, n) print("The value of " + str(a) + " power " + str(n) + " is " + str(res))''' #Recursion - Maximum Element in an Array #6 #2 #5 #1 #7 #4 #2 '''def find_max(a, n): if n == 1: return a[0] return max(a[n-1], find_max(a, n-1)) n = int(input()) a = [int(input()) for i in range(n)] print("Maximum element in the array is", find_max(a, n))''' #Recursion - Sum of Positive Odd Numbers 3,111 '''def sum_of_odd_numbers(arr, i, n): if i == n: return 0 else: if arr[i] > 0 and arr[i] % 2 == 1: return arr[i] + sum_of_odd_numbers(arr, i + 1, n) else: return sum_of_odd_numbers(arr, i + 1, n) n = int(input().strip()) arr = [int(input().strip()) for i in range(n)] print("Sum =", sum_of_odd_numbers(arr, 0, n))''' #n = int(input()) #Array 2D - Uniformity Matrix [2,4 5 5 4] '''n = int(input()) a = [] for i in range(n): a.append([int(x) for x in input().split()]) ecount = 0 ocount = 0 for i in range(n): for j in range(n): if a[i][j] % 2 == 0: ecount += 1 else: ocount += 1 if ecount == (n * n) or ocount == (n * n): print("Yes") else: print("No")''' #Array 2D - Magic Square [2 4 5 5 4] '''r = int(input()) a = [] for i in range(r): a.append([int(x) for x in input().split()]) d1 = 0 d2 = 0 for i in range(r): for j in range(r): if i == j: d1 += a[i][j] if i == r - j - 1: d2 += a[i][j] if d1 == d2: print("Yes") else: print("No")''' #Arrays 2D - Sum of rows and columns '''r = int(input()) c = int(input()) rw = [0] * r cw = [0] * c for i in range(r): row = list(map(int, input().split())) for j in range(c): x = row[j] rw[i] += x cw[j] += x print("The Sum of rows is", end = " ") mi = 0 m1 = 1 for i in range(r): print(rw[i], end = " ") if mi < rw[i]: mi = rw[i] m1 = i + 1 print("\nRow", m1, "has a maximum sum") print("The Sum of columns is", end = " ") mi = 0 m1 = 1 for i in range(c): if mi < cw[i]: mi = cw[i] m1 = i + 1 print(cw[i], end = " ") print("\nColumn", m1, "has the maximum sum") [3 3 1 6 8 2 5 1 3 8 2]''' #Arrays 2D - Spiral Pattern '''n = int(input().strip()) a = [] for i in range(n): row = [int(x) for x in input().strip().split()] a.append(row) round = int(n/2 + 0.5) for i in range(round): for j in range(i, n-i): print(a[i][j], end=" ") for j in range(i+1, n-i): print(a[j][n-i-1], end=" ") for j in range(n-i-2, i-1, -1): print(a[n-i-1][j], end=" ") for j in range(n-i-2, i, -1): print(a[j][i], end=" ") [4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]''' #Arrays 2D - Matrix Rotation '''n = int(input().strip()) mat = [] for i in range(n): mat.append(list(map(int, input().strip().split()))) for i in range(n): for j in range(i + 1, n): temp = mat[i][j] mat[i][j] = mat[j][i] mat[j][i] = temp for i in range(n): for j in range(n // 2): temp = mat[i][j] mat[i][j] = mat[i][n - j - 1] mat[i][n - j - 1] = temp for i in range(n): for j in range(n): print(mat[i][j], end=' ') print() [3 1 2 3 4 5 6 7 8 9]''' #Strings - Count the sum of numbers in a String [Fa33ce1] '''s = input() sum = 0 i = 0 while i < len(s): if s[i].isdigit(): j = i d = 0 while j < len(s) and s[j].isdigit(): d = d * 10 + int(s[j]) j += 1 i = j sum += d else: i += 1 print(sum)''' #Strings - Remove all characters in Second String that are present in First String '''a = input().strip() b = input().strip() result = "" for char in b: if char not in a: result += char print(result) #Motor #Motorcycle''' #Strings - Wordakshari a = input() b = "" c = "####" while a != c: if not b or a[0] == b[-1]: print(a) b = a a = input() #oracle #error #rohit ####
Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2 and start coding.
OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.
import sys
name = sys.stdin.readline()
print("Hello "+ name)
Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.
When ever you want to perform a set of operations based on a condition IF-ELSE is used.
if conditional-expression
#code
elif conditional-expression
#code
else:
#code
Indentation is very important in Python, make sure the indentation is followed correctly
For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.
mylist=("Iphone","Pixel","Samsung")
for i in mylist:
print(i)
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while condition
#code
There are four types of collections in Python.
List is a collection which is ordered and can be changed. Lists are specified in square brackets.
mylist=["iPhone","Pixel","Samsung"]
print(mylist)
Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.
myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
Below throws an error if you assign another value to tuple again.
myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)
Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.
myset = {"iPhone","Pixel","Samsung"}
print(myset)
Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.
mydict = {
"brand" :"iPhone",
"model": "iPhone 11"
}
print(mydict)
Following are the libraries supported by OneCompiler's Python compiler
Name | Description |
---|---|
NumPy | NumPy python library helps users to work on arrays with ease |
SciPy | SciPy is a scientific computation library which depends on NumPy for convenient and fast N-dimensional array manipulation |
SKLearn/Scikit-learn | Scikit-learn or Scikit-learn is the most useful library for machine learning in Python |
Pandas | Pandas is the most efficient Python library for data manipulation and analysis |
DOcplex | DOcplex is IBM Decision Optimization CPLEX Modeling for Python, is a library composed of Mathematical Programming Modeling and Constraint Programming Modeling |