Study Metrics
Study Metrics
Semester: 5th
a=0
b=1
c=1
if n==0 or n==1:
print("Yes")
else:
while c < n:
c=a+b
a=b
b=c
if n == c:
print("Yes")
else:
print("No")
def value(n):
x = int(n**0.5)
return x*x == n
def fibonacci(num):
if num < 0:
print("Give positive number")
else:
return value(5*num*num+4 or 5*num*num-4)
n=5
i=0
while(i<=n):
print(" " * (n - i) +"*" * i)
i += 1
4-c) Python Program to print a Triangle
num = int(input("Enter the range: "))
k = 1
print()
value = 65
for i in range(0, 5):
for j in range(0, i+1):
ch = chr(value)
print(ch, end=" ")
value = value + 1
print()
7-A) Using for loop create a list which contains
common elements in them.
for i in range(len(v)+1):
print(v[0:i])
9) Palindrome:
First method;
v="abba"
if v==v[::-1]:
print('yes')
else:
print('no')
second method;
v="qabccbaq"
l=int(len(v)/2)
x=1
for i in range(l):
if (v[i]==v[-(i+1)]):
x=1
else:
x=0
break
if (x==1):
print('palyndrome')
else:
print('not palyndrome')
10) Print the square value of the given number using
dictionary.
for val in l:
count+=val
if count in D:
count=D[count]
if count>=100:
print('succeed')
else:
print('failed')
list = [a,b,c]
16) Open the file "demofile2.txt" and append content to the file.
f = open("demofile2.txt", "a")
f.write("Now the file has more content!")
f.close()
import os
if os.path.exists("demofile.txt"):
os.remove("demofile.txt")
else:
print("The file does not exist")
print(a,b)
if(b==num):
print("yes this is the perfect cuberoot")
else:
print("no this is not a perfect cuberoot")
plt.plot(xpoints, ypoints)
plt.show()
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()
3)USING SCATTER
import sys
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
plt.scatter(x, y)
plt.show()
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()
4)USING GRID
import sys
import matplotlib
matplotlib.use('Agg')
import numpy as np
import matplotlib.pyplot as plt
x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])
5)USING BARS
import sys
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
plt.bar(x,y)
plt.show()
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()
6)USING HISTOGRAM
import sys
import matplotlib
matplotlib.use('Agg')
plt.hist(x)
plt.show()
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()