jagannathans92
BAN USERIn python:
while True:
x=(input("Enter the numbers to append:"))
if x=='q':
break
result=""
for i in x:
if i is '1':
out.append(i)
elif i is '0':
out.insert(-len(out),i)
result=(''.join(out))
print (result)
In python
=============
import json
x_inp=input("Enter the array:")
x=json.loads(x_inp)
y=int(input("Enter the index value:"))
def mini(x,y):
val=x[y]
summed=0
for i in range(0,(y+1)):
if x[i]<val:
summed+=x[i]
return summed
mini(x,y)
'''for two digit output'''
import json
x_inp=input("Enter the array:")
x=json.loads(x_inp)
y_inp=input("Enter the summed number to find combinations:")
y=int(y_inp)
def combinations(x,y):
out=[]
for i in x:
for j in x:
summed=i+j
if summed==y:
a=(i,j)
out.append(a)
return (print("All the combinations are ",out))
combinations(x,y)
===================
''' For three digits output'''
import json
x_inp=input("Enter the array:")
x=json.loads(x_inp)
y_inp=input("Enter the summed number to find combinations:")
y=int(y_inp)
def combinations(x,y):
out=[]
for i in x:
for j in x:
for k in x:
summed=i+j+k
if summed==y:
a=(i,j,k)
out.append(a)
return (print("All the combinations are ",out))
combinations(x,y)
In python:
a=input("ENter the string to reverse:")
arr=a.split()
def reverse(list1):
out=[]
for i in list1:
a=""
for j in range(1,(len(i)+1)):
a+=i[-j]
out.append(a)
res=' '.join(out)
return res
reverse(arr)
In python:
x=input("Please give an sentence:")
def format_word(statement):
words_array=statement.split()
output=[]
for i in range(0,len(words_array)):
if i % 2 ==0:
output.append(words_array[i].upper())
else:
out=''
in_value=words_array[i]
for i in in_value:
out=i+out
output.append(out)
return (' '.join(output))
format_word(x)
In python
inputs are given in list format(enclose in [])
correct me if am wrong
import json
x1=input("Enter the list:")
x=json.loads(x1)
def min_consecutive_one(list1):
count=0
for i in range(0,(len(list1)-1)):
if list1[i]==list1[i+1]:
count+=1
return count
min_consecutive_one(x)
In python for any list having only positive integers
correct me if any error
import json
x1=input("Enter the list:")
x=json.loads(x1)
def arrange_nonzero(list1):
list1.sort(reverse=True)
count=0
for i in list1:
if i!=0:
count+=1
print("Number of non-zero element:",count)
return list1
arrange_nonzero(x)
In python.
Correct me if am wrong
import json
x1=input("Enter the list:")
x=json.loads(x1)
y=int(input("enter the sum value:"))
setted=set()
#sett=set()
def sum_array(list1,value):
x=0
for i in range(0,len(list1)):
for j in range(0,len(list1)):
if i!=j:
x=list1[i]+list1[j]
if x==value:
setted.add((list1[i],list1[j]))
print("The repeated item is pair is ",setted)
sum_array(x,y)
In python its far easier:
below code for any given value:
def power(x,y):
return (x**y)
x=int(input("Enter the value to find power:"))
y=int(input("Enter the value of power:"))
power(x,y)
In python we can do it easily, not only for 3 emplyoee{1,2,3}, we can do it n number of employee:
correct me if any error.
The below code will give output for around 500 employee:
if u want to increase, kindly increase the count in both for loop(i.e 10001).
x1=int(input("ENter the reportable person's ID:"))
dic={}
key=[]
sep=[]
value=[]
for i in range(1,10001,2):
key.append(i)
print(key)
count=1
for i in range(2,10001):
#if count!=3:
sep.append(i)
# print(sep)
if count==3:
value.append(sep[:])
sep.clear()
count=0
count+=1
#print(key)
#print(value)
#print(len(value))
#print(len(key))
#print(value)
for i in range(1,len(value)):
dic[i]=value[i-1]
print(dic.get(x1))
In python.
- jagannathans92 March 02, 2018