Created
October 27, 2021 09:53
-
-
Save naemazam/64a5d466db32e3e56ad0c356930d211e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' There is a function f (x) defined on natural number, which is defined as | |
follows: | |
If x < 5, then f (x) = x; | |
If 5 < = x < 15, then f (x) = x + 6; | |
If x > = 15, then f (x) = x-6. | |
Try to write the function, enter the x value and return the corresponding f (x) | |
value. | |
[input form] the input line represents the natural number x. | |
[output form] the output line represents the calculation result f (x). If the | |
input data is illegal (e.g. negative integer), output "illegal input". | |
[sample input] 4 | |
[sample output] 4 | |
''' | |
def math(x): | |
if (x < 0): | |
return "illegal input" | |
elif(x<5): | |
return x | |
elif(5<=x and x<15): | |
return x+6 | |
elif(x>=15): | |
return x-6 | |
x=int(input("Enter Number: ")) | |
print(math(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment