- 2

Python

def h(n): f = 0 for i in range(1,n+1): if n%i == 0: f = f + 1 return(f == 2) The function h(n) given above returns True for a positive number n whenever: A) n is a multiple of 2 B) n is a composite number C) n is a prime number D) n has an even number

7th Feb 2018, 4:28 PM
darshan ks
darshan ks - avatar
2 Answers
+ 18
C) n is prime if n is prime the remainder will be =0 only for %1 & %n so if condition will become true twice and thus the f will be incremented twice by 1 making it 2 and returning ans true âœŒïžđŸ‘đŸ˜Ž
7th Feb 2018, 4:40 PM
🌛DT🌜
🌛DT🌜 - avatar
- 3
Ty
9th Feb 2018, 12:18 PM
darshan ks
darshan ks - avatar