pythonabhi
pythonabhi
a= 5
row=1
col=1
print(row,end=" ")
print()
OUTPUT:
Ques 1(b):
a=5
b=6
c=7
s=(a+b+c)/2
area=(s*(s-a)*(s-b)*(s-c))**0.5
OUTPUT:
i=1
sum=0
for i in range(1,n+1):
sum=sum+i
OUTPUT:
METHOD 2:
s=(n*(n+1))/2
OUTPUT:
QUES 3(B):
a=int(input("enter a number"))
product=a*b
if product>1000:
sum=a+b
else:
OUTPUT:
QUES 2(a):
a=int(input("enter a number"))
num1=0
num2=1
print(num1,num2,end=" ")
for i in range(a-2):
num1,num2=num2,(num1+num2)
print(num2,end=" ")
OUTPUT:
QUES 2(C):
for i in range(N1,N2+1):
if i>0:
is_prime=True
for j in range(2,int(i**0.5)+1):
if i%j==0:
is_prime=False
break
if is_prime:
print(i)
OUTPUT:
QUES 2 ( B ):
num1=int(input("enter a number"))
num2=int(input("enter another number"))
l=len(str(abs(num)))
print(sum_of_powers)
OUTPUT:
QUES 4(A):
else:
OUTPUT:
QUES 4(B):
count = main_string.count(sub_string)
OUTPUT:
QUES 5(A):
def factorial(num):
if num==0 or num==1:
return 1
else:
return num*factorial(num-1)
if num<0:
else:
result=factorial(num)
OUTPUT:
QUES 5(B):
if age>18:
print(name)
OUTPUT:
QUES 6(A):
import os
f=open(os.path.join("text1"),"r")
length=len(f.read().split(" "))
f.close()
f2=open(os.path.join("text2"),"r")
numfile=open("myfile.txt","w")
scores=[]
for x in f2:
scores.append(int(x.split(" ")[1]))
numfile.write(str(sum(scores)/len(scores)))
f2.close()
numfile.close()
QUES 6(C):
try:
f3=open("mynewfile.txt","r")
print(f3.read())
f3.close()
except Exception as e:
print(e)
OUTPUT:
QUES 7(A):
class Student:
self.name = name
self.percentage = percentage
self.percentage = new_percentage
def is_passed(self):
return True
else:
return False
if student.is_passed():
else:
student.update_percentage(new_percentage)
if student.is_passed():
else:
OUTPUT:
QUES 7(B):
import math
return compound_interest
rate = float(input("Enter the annual interest rate (in percentage): ")) / 100
OUTPUT:
QUES 8(A):
import numpy as np
X=np.arange(0,2*np.pi,0.1)
Y=np.sin(X)
plt.plot(X,Y)
plt.show()
OUTPUT:
QUES 8(B):
import random
else:
OUTPUT:
QUES 9:
list1 = [1, 3, 5]
list2 = [2, 4, 6]
print(merged_list)
OUTPUT:
QUES 10:
def merge_sorted_lists(l1,l2):
return sorted(l1+l2)
print(merge_sorted_lists([1,2,5],[0,3,8]))
def flatten(l):
newlist=[]
for i in range(len(l)):
if type(l[i])!=list:
newlist.append(l[i])
else:
l1=flatten(l[i])
newlist.extend(l1)
return newlist
print(flatten([1,[2,[3,4],5],6]))
OUTPUT: