-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 01 - divide_or_square.py
More file actions
41 lines (31 loc) · 1.06 KB
/
Day 01 - divide_or_square.py
File metadata and controls
41 lines (31 loc) · 1.06 KB
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
"""
Created on Thu Apr 7 01:52:31 2022
@author: GRACE ESTRADA
Day 1 50 Days of Python
Write a function called divide_or_square that takes one argument (a number),
and returns the square root of the number if it is divisible by 5,
returns its remainder if it is not divisible by 5.
For example, if you pass 10 as an argument, then your function should return 3.16 as the square root.
"""
# Importing functions
from math import sqrt
# Defining divide_or_square function
def divide_or_square(n):
"""
Takes one argument (a number), and returns the following:
- square root of the number if it is divisible by 5,
- remainder if it is not divisible by 5
:param n(int): a number to be divided or squared
:return: int
"""
if n % 5 == 0:
return sqrt(n)
else:
return n % 5
#Execute the function with user input
prompt = ''
while prompt.lower() != 'no':
user_input = int(input('\nPlease input a number: '))
print(divide_or_square(user_input))
prompt = input('Continue? Yes or No?: ')
input('\nPress ENTER to exit')