KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

Write a function called ice_water that takes a number as input. Perform the following operations:

  • If the number is divisible by 3, then it should return "ice".
  • If it is divisible by 5, then it should return "water".
  • If it is divisible by both 3 and 5, then it should return "icewater".
  • Otherwise, it should return the same number.

Python Functions

1 Like

Answer

def ice_water(n):
    if n % 3 == 0 and n % 5 == 0:
        return "icewater"
    elif n % 3 == 0:
        return "ice"
    elif n % 5 == 0:
        return "water"
    else:
        return n

num = int(input("Enter a number: "))
result = ice_water(num)
print(result)

Output

Enter a number: 15
icewater

Enter a number: 9
ice

Enter a number: 20
water

Answered By

3 Likes


Related Questions