big_cee223

ตัวอย่างข้อสอบ Computer Programming ข้อที่ 2

Dec 26th, 2020 (edited)
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. #ตัวอย่างข้อสอบ Computer Programming ข้อที่ 2
  2. #Part 1
  3. num=int(input("Enter a number (10-99): "))
  4. while num<10 or num>99:
  5.     print("Invalid number!")
  6.     num=int(input("Enter a number (10-99): "))
  7. #Part 2
  8. num_str=str(num)
  9. first_str=num_str[0]
  10. second_str=num_str[1]
  11. a=int(first_str)
  12. b=int(second_str)
  13. print(f"""a = {first_str} and b = {second_str}\n""")
  14. if a>5 and b>5: #a>5
  15.     print("""Less than 5 = 0
  16. Equal to 5 = 0
  17. More than 5 = 2""")
  18.  
  19. if a>5 and b==5:
  20.         print("""Less than 5 = 0
  21. Equal to 5 = 1
  22. More than 5 = 1""")
  23. if a>5 and b<5:
  24.             print("""Less than 5 = 1
  25. Equal to 5 = 0
  26. More than 5 = 1""")
  27. if a<5 and b<5: #a<5
  28.             print("""Less than 5 = 2
  29. Equal to 5 = 0
  30. More than 5 = 0""")
  31. if a<5 and b==5:
  32.             print("""Less than 5 = 1
  33. Equal to 5 = 1
  34. More than 5 = 0""")
  35. if a<5 and b>5:
  36.             print("""Less than 5 = 1
  37. Equal to 5 = 0
  38. More than 5 = 1""")
  39. if a==5 and b>5: #a==5
  40.             print("""Less than 5 = 0
  41. Equal to 5 = 1
  42. More than 5 = 1""")
  43. if a==5 and b==5:
  44.             print("""Less than 5 = 0
  45. Equal to 5 = 2
  46. More than 5 = 0""")
  47. if a==5 and b<5:
  48.             print("""Less than 5 = 1
  49. Equal to 5 = 1
  50. More than 5 = 0""")
  51.  
  52. '''
  53. #Tools
  54. print(first_str, second_str, sep='/')
  55. print(first_int, second_int, sep='/')
  56. '''
  57.  
  58.  
Add Comment
Please, Sign In to add comment