0% found this document useful (0 votes)
24 views1 page

Exercise 5.9

Uploaded by

Faizpradana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

Exercise 5.9

Uploaded by

Faizpradana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

In 

[8]:
#number1

count=0

for i in range(1,101):

if (i**2)%10==1:

count=count+1

print('The square numbers ended in a 1 are', count, ' numbers')

The square numbers ended in a 1 are 20

In [4]:
#number2

c1 = 0

c2 = 0

for i in range (1,101):

if (i**2)%10==4:

c1=c1+1

if (i**2)%10==9:

c2=c2+1

print('The square numbers ended in a 4 are ', c1, 'numbers')

print('The square numbers ended in a 9 are ', c2, 'numbers')

13

17

23

27

33

37

43

47

53

57

63

67

73

77

83

87

93

97

The square numbers ended in a 4 are 20 numbers

The square numbers ended in a 9 are 20 numbers

In [7]:
#number3

import math

c = int(input('Enter a number :'))

lg = math.log(c)

lg2 = round(lg,2)

for i in range (1,c+1):

num = 1/i

c=c-lg2

print('The result is', round(c,2))

Enter a number :9

The result is 6.8

In [10]:
#number4

sm = 0

for i in range (1,2001):

if i%2==0:

sm=sm-i

else :

sm=sm+i

print('The sum of it is', sm)

The sum of it is -1000

In [11]:
#number5

a = int(input('Enter a number :'))

for i in range(1,a+1):

if i%a==0:

a=a+i

print('The sum of it is', a)

Enter a number :9

The sum of it is 18

In [2]:
#number6

print('The perfect numbers between 1 to 10000 are :')

for i in range (1,10001):

c=0

for j in range(i):

if i%(j+1)==0:

c=c+(j+1)

d=c-i

if d==i:

print(d, end=' ')

The perfect numbers between 1 to 10000 are :

6 28 496 8128

In [2]:
#number7

sf = int(input('Enter a number :'))

fac = 1

if sf < 0:

print("Sorry, factorial doesn't exist for negative numbers")

elif sf == 0:

print('The factorial of 0 is 1')

else:

for i in range(1,sf+1):

fac = fac*i

print('The factorial of', sf, 'is', fac)

Enter a number :5

The factorial of 5 is 120

In [3]:
#number8

x=1

y=2

z=3

print('x,y,z are',x,y,z)

x,y,z = y,z,x

print('now x,y,z are',x,y,z)

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 = []

for i in range (1,11):

scr = int(input('Enter a score : '))

if scr > 100:

print('A value over 100 has been entered')

scores.append(scr)

scores.sort()

avrg = sum(scores)/10

hg = scores[-1]

mn = scores[0]

hg2 = scores[-2]

avrg2 = sum(scores[3:])/8

print('The highest and lowest scores are', hg, 'and', mn)

print('The average of the score is', avrg)

print('The second highest of the scores', hg2)


print('The average of the scores without the two lowest scores is', avrg2)

Enter a score : 90

Enter a score : 70

Enter a score : 80

Enter a score : 100

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 highest and lowest scores are 100 and 70

The average of the score is 82.0

The second highest of the scores 90

The average of the scores without the two lowest scores is 75.0

In [46]:
#number11

inp=int(input('Enter a number: '))

rs = 1

for i in range (1,inp+1):

rs = rs*i

print('The factorial of', inp, 'is',rs)

Enter a number: 5

The factorial of 5 is 120

In [1]:
#number12

from random import randint

print("It's a 'Guess a Number' game")

scrs = 0

for g in range (1,6):

rndm = randint(1,10)

print('Take a number guess from 1 to 10!')

nm = int(input())

if nm != rndm :

print('Your guess is wrong')


scrs -= 1

elif nm == rndm :

print('Your guess is correct!')

scrs += 10

print('Your total scores is', scrs)

It's a 'Guess a Number' game

Take a number guess from 1 to 10!

Your guess is wrong

Take a number guess from 1 to 10!

Your guess is wrong

Take a number guess from 1 to 10!

Your guess is wrong

Take a number guess from 1 to 10!

Your guess is wrong

Take a number guess from 1 to 10!

Your guess is wrong

Your total scores is -5

In [3]:
#number13

from random import randint

rg = 0

wr = 0

for i in range (1,11):

a=randint(1,10)

b=randint(1,10)

print('Question ', i, ' : ', a, 'x', b, '=')

ans = int(input())

c=a*b

if ans==c:

print("Yeay, your answer is right!")

rg += 1

else :

print("Sorry, your answer is wrong")

wr += 1

print('You got', rg, 'question(s) right and', wr,'question(s) wrong')

Question 1 : 7 x 3 =

21

Yeay, your answer is right!

Question 2 : 7 x 5 =

35

Yeay, your answer is right!

Question 3 : 1 x 7 =

Yeay, your answer is right!

Question 4 : 2 x 6 =

12

Yeay, your answer is right!

Question 5 : 6 x 10 =

10

Sorry, your answer is wrong

Question 6 : 4 x 9 =

36

Yeay, your answer is right!

Question 7 : 10 x 2 =

20

Yeay, your answer is right!

Question 8 : 9 x 10 =

90

Yeay, your answer is right!

Question 9 : 3 x 8 =

24

Yeay, your answer is right!

Question 10 : 1 x 4 =

Yeay, your answer is right!

You got 9 question(s) right and 1 question(s) wrong

In [ ]:
#number14

You might also like