-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ07.py
73 lines (56 loc) · 1.45 KB
/
Q07.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Aledutron
SPPU 2019 FE PPS Lab
SPPU First Year (FE) Programming and Problem Solving (PPS) Lab Assignments (2019 Pattern)
Youtube PPS Playlist Link: https://youtube.com/playlist?list=PLlShVH4JA0osTzddxh-2s1yaigpyp6DRx&si=5RWSN_MmtX1FACb1
Problem Statement:
Q7
To accept the number and Compute
a) square root of number,
b) Square of number,
c) Cube of number
d) check for prime,
d) factorial of number
e) prime factors
Explaination Video Link: https://www.youtube.com/watch?v=g7Qm6EJgeUQ&list=PLlShVH4JA0osTzddxh-2s1yaigpyp6DRx&index=8&pp=iAQB
"""
#Setup Code
import sys
sys.stdin = open('input.txt','r')
sys.stdout = open('output.txt','w')
###########################################
#Real Code Starts
import math
def isPrime(n):
# 2 - (n-1) is dividing n or not
for i in range(2,n):
if n%i == 0:
return False
return True
def fact(n):
if n <= 1:
return 1
else:
return n * fact(n-1)
def findprimefactors(n):
primelist = []
for i in range(2,n):
if isPrime(i) and n%i == 0:
primelist.append(i)
if isPrime(n):
primelist.append(n)
return primelist
for i in range(int(input())):
n = int(input())
print(f"Square root of {n} = {math.sqrt(n)}")
print(f"Square of {n} = {n**2}")
print(f"cube of {n} = {n**3}")
if isPrime(n):
print(f"{n} is prime")
else:
print(f"{n} is not prime")
print(f"factorial of {n} is {fact(n)}")
print(f"Prime factors of {n} are :")
for i in findprimefactors(n):
print(i)
print()