fork download
  1. def tekaTekiTeko(batas: int):
  2. if not isinstance(batas, int) or batas < 20:
  3. raise ValueError("Parameter batas harus berupa bilangan bulat positif (unsigned integer) dan minimal 20")
  4.  
  5. for i in range(1, batas + 1):
  6. if i % 2 == 0 and i % 3 == 0 and i % 5 == 0:
  7. print("TekaTekiTeko")
  8. elif i % 2 == 0 and i % 3 == 0:
  9. print("TekaTeki")
  10. elif i % 2 == 0 and i % 5 == 0:
  11. print("TekaTeko")
  12. elif i % 3 == 0 and i % 5 == 0:
  13. print("TekiTeko")
  14. elif i % 2 == 0:
  15. print("Teka")
  16. elif i % 3 == 0:
  17. print("Teki")
  18. elif i % 5 == 0:
  19. print("Teko")
  20. else:
  21. print(i)
  22.  
  23. print("\n===== Test parameter valid =====\n")
  24.  
  25. try:
  26. tekaTekiTeko(30)
  27. except ValueError as e:
  28. print(f"Error: {e}")
  29.  
  30. print("\n===== Test parameter tidak valid =====\n")
  31.  
  32. try:
  33. tekaTekiTeko(19)
  34. except ValueError as e:
  35. print(f"Error: {e}")
Success #stdin #stdout 0.08s 13964KB
stdin
Standard input is empty
stdout
===== Test parameter valid =====

1
Teka
Teki
Teka
Teko
TekaTeki
7
Teka
Teki
TekaTeko
11
TekaTeki
13
Teka
TekiTeko
Teka
17
TekaTeki
19
TekaTeko
Teki
Teka
23
TekaTeki
Teko
Teka
Teki
Teka
29
TekaTekiTeko

===== Test parameter tidak valid =====

Error: Parameter batas harus berupa bilangan bulat positif (unsigned integer) dan minimal 20