Mình chỉ nhớ như vậy thôi, đang dùng điện thoại nên hơi ngại ![:smile: :smile:](https://daynhauhoc.com/images/emoji/twitter/smile.png?v=5)
Sorry mình nhớ nhầm, có while ![:smile: :smile:](https://daynhauhoc.com/images/emoji/twitter/smile.png?v=5)
chỗ nối str thì trong python phải convert int sang str
def result(a):
s = ""
i = 2
if type(a) == 'int':
while i <= a:
if a % i == 0:
s = s + str(i) + "*"
a = a / i
else:
i += 1
else:
s = "No integer entered"
return s
if __name__ == '__main__':
a = input("Enter a number: ")
print(result(a))
có thể dùng đoạn code này để bắt buôc nhập vào int:
while True:
a = raw_input("enter a number: ")
if type(a) == 'int':
break
thì trong hàm result ko cần kiểm tra a là int hay ko nữa, nhg theo mình thì để cả 2 chỗ cũng được, để dùng lại hàm result ở chỗ khác ko bị lỗi