a = 20
def convert(a) :
b = 20
a = a+b
convert(10)
print(a)
(a) 10 (b) 20 (c) 30 (d) Error
def EvenOdd()
for i in range(5) :
num = int(input("Enter a number ")
if num/2==0 :
print("Even")
else:
print("Odd")
EvenOdd()
def EvenOdd() :
for i in range(5) :
num = int(input("Enter a number "))
if num%2==0 :
print("Even")
else:
print("Odd")
EvenOdd()
def puzzle(W,N):
result=""
for i in range(len(W)):
if (i+1)%N==0:
result+="_"
else:
result+=W[i]
return result
x=puzzle("TELEVISION",3)
print(x)
| Average of Eng, Math, Science | Grade |
|---|---|
| >=90 | A |
| <90 but >=60 | B |
| <60 | C |
def showGrades(S):
for i,j in S.items():
avg=(j[0]+j[1]+j[2])/3
if avg>=90:
print(i,"- A")
elif avg>=60 and avg<90:
print(i,"- B")
elif avg<60:
print(i,"- C")
D={"Amit":[92,86,64],"Nagma":[65,42,43],"David":[92,90,88]}
showGrades(D)
def callon(b=20, a=10):
b=b+a
a=b-a
print(b,"#",a)
return b
x=100
y=200
x=callon(x,y)
print(x,"@",y)
y=callon(y)
print(x,"@",y)
300 # 100 300 @ 200 210 # 200 300 @ 210
def max_num(L):
max=L(0)
for a in L:
if a>max
max=a
return max
def max_num(L):
max=L[0]
for a in L:
if a>max:
max=a
return max
def short_sub(lst,n):
for i in range(0,n):
if len(lst)>4:
lst[i]=lst[i]+lst[i]
else:
lst[i]=lst[i]
subject=['CS','HINDI','PHYSICS','CHEMISTRY','MATHS']
short_sub(subject,5)
print(subject)
a=30
def call(x):
global a
if a%2==0:
x+=a
else:
x-=a
return x
x=20
print(call(35),end="#")
print(call(40),end="@")
def makenew(mystr):
newstr = ""
count = 0
for i in mystr:
if count%2 != 0:
newstr = newstr + str(count)
else:
if i.lower():
newstr = newstr + i.upper()
else:
newstr = newstr + i
count += 1
print(newstr)
makenew("No@1")
Example : If Sample Input data of the list is : L= [10, 20, 30, 40, 35, 55] Output will be : L= [11, 21, 31, 41, 34,54]
def EOReplace(L):
for i in range(len(L)):
if L[i]%2==0:
L[i]=L[i]+1
else:
L[i]=L[i]-1
print(L)
or
def EOReplace():
L=[]
ch = 'y'
while ch == 'y' or ch == 'Y':
x = int(input('give item'))
L.append(x)
ch= input('do you want to enter more y/n ')
for i in range(len(L)):
if L[i]%2==0:
L[i]=L[i]+1
else:
L[i]=L[i]-1
print(L)