Same Question Framed With More Difficulty Level As Follows:: Program
Same Question Framed With More Difficulty Level As Follows:: Program
another or not?
PROGRAM:-
MainString=input("Enter string:")
sub_str=input("Enter word:")
if(MainString.find(sub_str)==-1):
print("Substring not found in string!")
else:
print("Substring in string!")
# order of number
order = len(str(num))
# initialize sum
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num)
PROGRAM:-
def palindrome(s):
v = []
for i in s:
if vowel(i):v.append(i)
if len(v)== 0: print("-1")
else:
x = v[::-1]
f = 1
for i in range(len(x)):
if x[i]!= v[i]:
f = 0
break
if f == 1: print("YES")
else: print("NO")
s = input("Enter string:")
palindrome(s.strip())
PROGRAM:-
x = 10
y = 50
x, y = y, x
Second solution:
X = x+y
y=x-y
x= x-y
PROGRAM:-
x = 10
y = 50
x = x + y
y = x - y
x = x - y
Third solution:
X = x^y
Y=x^y
X=x^y
PROGRAM:-
x = 10
y = 50
x = x ^ y
y = x ^ y
x = x ^ y
Fourth solution:
X = x*y
Y=x/y
X=x/y
PROGRAM:-
x = 10
y = 50
x = x + y
y = x - y
x = x – y
print("After Swapping: x =", x, " y =", y);
• Write a program to find how many are the leap years in range of
1300-2000.
For example: 1300, 1700, 1900 are not a leap year.
PROGRAM:-
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
arr_max = arr[low]
arr_min = arr[low]
if low == high:
arr_max = arr[low]
arr_min = arr[low]
arr_max = arr[low]
arr_min = arr[high]
else:
arr_max = arr[high]
arr_min = arr[low]
else:
arr =[sub1,sub2,sub3,sub4,sub5]
high = len(arr) - 1
low = 0
arr =[sub1,sub2,sub3,sub4,sub5]
b = sorted(list(set(a)),reverse=True)
Program:
height = int(input())
for i in range(1,height+1):
print(('* '*i))
• Printing Triangle
Program:
height = int(input())
for i in range(1,height+1):
print(('* '*i).center(height*2))
• Number Pattern like pyramid
Program:
height = int(input())
for i in range(1,height+1):
[print(j,end=' ') for j in range(1,i+1)]
print('\r')
• Numbers pattern without re assigning the values means Number pattern with
distinct values like pyramid.
Program:
height = int(input())
num = 1
for i in range(1,height+1):
for _ in range(1,i+1):
print(num, end=' ')
num += 1
print('\r')
Program:
height = int(input())
s = 'A'
for i in range(1,height+1):
ns = ''
for j in range(1,i+1):
ns += s
s = chr(ord(s)+1)
print(' '.join(ns).center(height*2))
for i in range(height,0,-1):
ns = ''
for j in range(1,i+1):
ns += s
s = chr(ord(s)+1)
print(' '.join(ns).center(height*2))