Exercise 5.9
Exercise 5.9
[8]:
#number1
count=0
for i in range(1,101):
if (i**2)%10==1:
count=count+1
In [4]:
#number2
c1 = 0
c2 = 0
if (i**2)%10==4:
c1=c1+1
if (i**2)%10==9:
c2=c2+1
13
17
23
27
33
37
43
47
53
57
63
67
73
77
83
87
93
97
In [7]:
#number3
import math
lg = math.log(c)
lg2 = round(lg,2)
num = 1/i
c=c-lg2
Enter a number :9
In [10]:
#number4
sm = 0
if i%2==0:
sm=sm-i
else :
sm=sm+i
In [11]:
#number5
for i in range(1,a+1):
if i%a==0:
a=a+i
Enter a number :9
The sum of it is 18
In [2]:
#number6
c=0
for j in range(i):
if i%(j+1)==0:
c=c+(j+1)
d=c-i
if d==i:
6 28 496 8128
In [2]:
#number7
fac = 1
if sf < 0:
elif sf == 0:
else:
for i in range(1,sf+1):
fac = fac*i
Enter a number :5
In [3]:
#number8
x=1
y=2
z=3
print('x,y,z are',x,y,z)
x,y,z = y,z,x
x,y,z are 1 2 3
now x is 2 3 1
In [3]:
#number9
a=0
b=0
c=0
for i in range(1,1001):
if (round(i**(1/2))**2==i):
a=a+1
elif (round(i**(1/3))**3==i):
b=b+1
elif (round(i**(1/5))**5==i):
c=c+1
d=1000-(a+b+c)
print('There are', d, 'integers between 1 to 1000 that are not perfect squares, perfect cubes, or perfect fifth powers')
There are 960 integers between 1 to 1000 that are not perfect squares, perfect cubes, or perfect fifth powers
In [2]:
#number10
scores = []
scores.append(scr)
scores.sort()
avrg = sum(scores)/10
hg = scores[-1]
mn = scores[0]
hg2 = scores[-2]
avrg2 = sum(scores[3:])/8
Enter a score : 90
Enter a score : 70
Enter a score : 80
Enter a score : 80
Enter a score : 80
Enter a score : 90
Enter a score : 70
Enter a score : 80
Enter a score : 80
The average of the scores without the two lowest scores is 75.0
In [46]:
#number11
rs = 1
rs = rs*i
Enter a number: 5
In [1]:
#number12
scrs = 0
rndm = randint(1,10)
nm = int(input())
if nm != rndm :
elif nm == rndm :
scrs += 10
In [3]:
#number13
rg = 0
wr = 0
a=randint(1,10)
b=randint(1,10)
ans = int(input())
c=a*b
if ans==c:
rg += 1
else :
wr += 1
Question 1 : 7 x 3 =
21
Question 2 : 7 x 5 =
35
Question 3 : 1 x 7 =
Question 4 : 2 x 6 =
12
Question 5 : 6 x 10 =
10
Question 6 : 4 x 9 =
36
Question 7 : 10 x 2 =
20
Question 8 : 9 x 10 =
90
Question 9 : 3 x 8 =
24
Question 10 : 1 x 4 =
In [ ]:
#number14