0% found this document useful (0 votes)
17 views10 pages

Programs

Uploaded by

Bhanu Varma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views10 pages

Programs

Uploaded by

Bhanu Varma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

<<< SINGLE DIGIT

n=int(input("enter the n:"))


if n%2 !=0:
temp=n//2
else:
temp=(n-2)/2
if n // 10 ==0:
temp=n
print(int(temp))

<<<SUPERIOR ELEMENT
arr=[8,10,6,2,9,7]
count=0
for i in range(len(arr)-2,-1,-1):
min=arr[len(arr) - 1]
if arr[i] > min:
count +=1
min=arr[i]
print(count)

<<< BIRTHDAY CAKE


n=int(input())
op=((n*(n+1))/2 + 1) % 10000000007
print(op)

<<< LOWER AND UPPER


str1="bhAnU"
low=0
high=0
for i in range(len(str1)):
if 124 > ord(str1[i]) > 96:
low +=1
elif 91 > ord(str1[i]) > 65:
high +=1
if low > high:
print(str1.lower())
else:
print(str1.upper())

<<< ROCK PAPER SCISSORS

M=str(input())
dic={"scissors":"rock","paper":"scissor","rock":"paper"}
if M=="scissors":
print(dic["scissors"])
elif M=="paper":
print(dic["paper"])
elif M=="rock":
print(dic["rock"])
<<< META NUMBER
n=int(input())
count=0
for i in range(n+1):
if (i%1==0) and (i%2==0) and (i%4==0) and (i%8==0) and (i%10 !=0):
count +=1
print(count)

<<< COMPLETE HOUR

N=int(input())
arr=[]
for i in range(N):
elem=int(input())
arr.append(elem)
count=0
for k in range(len(arr)):
if arr[k] > 60:
temp=arr[k] % 60
arr.append(temp)
for i in range(len(arr)):
for j in range(i+1,len(arr)):
if arr[i] < 60 and arr[i]+arr[j]==60:
count +=1
if count==0:
print("NO HOURS")
else:
print(count)

<<< SUM OF LEADERS (SUPIRIOR ELEMENT SUM)

arr=[16,17,4,3,5,2]
n=len(arr)
min=temp=arr[n-1]
sum=0
for i in range(n-2,-1,-1):
if arr[i] > min:
sum += arr[i]
min=arr[i]
print(sum+temp)

4).<<< DIAGONAL

import math
T=int(input("T:"))
for i in range(T):
L=int(input("L:"))
B=int(input("B:"))
dia=round(math.sqrt(L**2 + B**2))
print(dia)

5).<<< BOB CANDIES

arr=[8,5,16,7,10]
M=int(input("M:"))
arr.sort()
sum=0
count=0
for i in range(len(arr)):
if arr[i] % 5==0:
count +=1
temp=count
elif sum < M:
sum += arr[i]
count=count + 1
temp=count - 1
print(temp)

6).<<< BALL REBOUNDED HEIGHT

H=int(input())
V=int(input())
Vn=int(input())
Hf=H * ((V/Vn)**2)
print(Hf)

7).<<< CHAR REPLACE

str1=str(input("enter the word:"))


ch1=str(input("enter ch1:"))
ch2=str(input("enter ch2:"))
res=""
for i in range(len(str1)):
if str1[i] == ch1:
res += ch2
elif str1[i] == ch2:
res += ch1
else:
res += str1[i]
print(res)

8).<<< COIN TOSS

def Toss(S):
conseq_head=0
score=0
for toss in S:
if toss=="H":
score +=2
conseq_head +=1
elif toss=="T":
score -=1
conseq_head =0
if conseq_head==3:
break
return score
S=str(input())
print(Toss(S))

10).<<< BINARY CONVERTION

def Binary(n):
res=""
ans=""
while n>0:
rem=n%2
res += str(rem)
n=n//2
for i in range(len(res)-1,-1,-1):
ans += res[i]
return ans
n=int(input())
print(Binary(n))

11).<<< DIFFERENCE IN SPACE

def Spaces(s1,s2):
s1_count=0
s2_count=0
for space in s1:
if space==" ":
s1_count +=1
for space in s2:
if space==" ":
s2_count +=1
res=abs(s1_count - s2_count)
if res % 2==0:
print("Even:",res)
else:
print("Odd:",res)
return ""
s1=str(input())
s2=str(input())
print(Spaces(s1,s2))

12).<<< FIBONACCI SERIES

def fibonacc(n):
n1=0
n2=1
print(n1,n2,end=" ")
for i in range(2,n):
n3=n1+n2
print(n3,end=" ")
n1=n2
n2=n3
return ""
n=int(input())
print(fibonacc(n))

13).<<< FILE VERSION

def File_version(size,S):
latest_version=-1
for file in S:
if file.startswith("File_"):
version_num=file[5:]
if version_num.isdigit():
version=int(version_num)
ans=max(version,latest_version)
return ans
size=int(input())
S=[]
for i in range(size):
elem=str(input())
S.append(elem)
print(File_version(size,S))

14).<<< DIVISOR,REMAINDER,QUOETIENT

def DQR(n,arr,D,Q,R):
value=(D*Q)+R
for i in arr:
if i==value:
res=arr.index(i)
break
else:
res=-1
return res
n=int(input())
arr=[]
for i in range(n):
elem=int(input())
arr.append(elem)
D=int(input())
Q=int(input())
R=int(input())
print(DQR(n,arr,D,Q,R))
15).<<< SECOND LARGEST

def Second_largest(n,arr):
res=list(set(arr))
count=0
for i in range(n):
if arr[i]==res[-2]:
count +=1
return count
n=int(input())
arr=[]
for i in range(n):
elem=int(input())
arr.append(elem)
print(Second_largest(n,arr))

16).<<< ODD_EVEN

def Odd_Even(n):
p=n
product=1
sum=0
while n>0:
rem=n%10
product *= rem
sum += rem
n=n//10
if p%2 !=0:
temp=product
else:
temp=sum
return temp
n=int(input())
print(Odd_Even(n))

17).<<< FOOTBALL

def Foot_Ball(arr):
count_A=0
count_B=0
for i in range(len(arr)):
if arr[i]=="TeamA":
count_A +=1
if arr[i]=="TeamB":
count_B +=1
res=max(count_A,count_B)
if res==count_A and res==count_B:
print("Tie")
elif res==count_A:
print("TeamA")
elif res==count_B:
print("TeamB")
n=int(input())
arr=[]
for i in range(n):
elem=str(input())
arr.append(elem)
Foot_Ball(arr)

18).<<< POSITIVE MID ELEMENT

def Positive_mid(arr):
n=len(arr)
if n%2 !=0:
i=n//2
else:
i=(n//2)-1
print(arr[i])
size=int(input())
arr=[]
for i in range(size):
elem=int(input())
arr.append(elem)
Positive_mid(arr)

19).<<< PRIME ADD

def Prime_add(arr):
n=len(arr)
sum=0
for num in range(n+1):
if num>1:
for i in range(2,num):
if num%i==0:
break
else:
sum +=arr[num]
print(sum)
size=int(input("size:"))
arr=[]
for i in range(size):
elem=int(input())
arr.append(elem)
Prime_add(arr)

20).<<< LONGEST SEQUENCE

def Longest_seq(S):
count_n=0
res=-1
for char in s:
if char.isalpha():
count_n +=1
elif char==".":
count_n=0
res=max(count_n,res)
print(res)
S=str(input())
Longest_seq(S)

21).<<< SUM_XOR

def Sum_Xor(arr):
if len(arr)==0:
return -1
if len(arr)==1:
return arr[0]
sum=arr[0]
xor=arr[1]
for i in range(2,len(arr)):
if i%2==0:
sum = sum + arr[i]
else:
xor = xor ^ arr[i]
res=sum+xor
print(res)
n=int(input())
arr=[]
for i in range(n):
elem=int(input())
arr.append(elem)
Sum_Xor(arr)

22)<<< VOWEL FACTOIAL

def Vowel_Factorial(S):
n=0
S=S.lower()
for i in S:
if i.isalpha() and i!="a" and i !="e" and i !="i" and i !="o" and i!="u":
n +=1
fact=1
for i in range(1,n+1):
fact=fact*i
print(fact)
S=str(input("str:"))
Vowel_Factorial(S)

23).<<< VOWEL OCCURENCE


def Vowel_Occurence(S):
S=S.lower()
for i in range(1,len(S)-1):
if ((S[i]=="a" or S[i]=="e" or S[i]=="i" or S[i]=="o" or S[i]=="u")
and
(S[i-1]!="a" or S[i-1]!="e" or S[i-1]!="i" or S[i-1]!="o" or S[i-1]!="u")
and
(S[i+1]!="a" or S[i+1]!="e" or S[i+1]!="i" or S[i+1]!="o" or S[i+1]!="u")):
res=S.replace(S[i],"")
print(res)
S=str(input("str:"))
Vowel_Occurence(S)

24).<<< CARRY_COUNT

def Carry_count(n,m):
carry=0
count=0
while n>0 and m>0:
rem_1=n%10
rem_2=m%10
res=rem_1 + rem_2 + carry
if res >= 10:
carry +=1
count +=1
n=n//10
m=m//10
print(count)
n=int(input("n:"))
m=int(input("m:"))
Carry_count(n,m)

You might also like