Hướng dẫn find the difference between the sum of odd and even numbers from a list of 5 numbers in python - tìm sự khác biệt giữa tổng các số lẻ và số chẵn từ danh sách 5 số trong python
Xem thảo luận Show
Cải thiện bài viết Lưu bài viết Xem thảo luận Cải thiện bài viết Lưu bài viết Đọc Examples: Input : 1212112 Output : Yes Explanation:- the odd position element is 2+2+1=5 the even position element is 1+1+1+2=5 the difference is 5-5=0.so print yes. Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no. Bàn luậnOne by one traverse digits and find the two sums. If the difference between two sums is 0, print yes, else no. Python3Cho một số nguyên dài, chúng ta cần tìm xem sự khác biệt giữa tổng các chữ số lẻ và tổng các chữ số chẵn là 0 hay không. Các chỉ mục bắt đầu từ số 0 (0 chỉ mục dành cho chữ số ngoài cùng bên trái). Phương pháp 1: Từng một chữ số Traverse và tìm hai tổng. Nếu sự khác biệt giữa hai tổng là 0, in có, khác không.
Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.0 Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.1__12 Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.4 = Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.6 Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.7 Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.8 = Input : test_list = [345, 893, 1948, 34, 2346] Output : Odd digit sum : 36 Even digit sum : 40 Explanation : 3 + 5 + 9 + 3 + 1 + 9 + 3 + 3 = 36, odd summation.0 Input : test_list = [345, 893, 1948, 34, 2346] Output : Odd digit sum : 36 Even digit sum : 40 Explanation : 3 + 5 + 9 + 3 + 1 + 9 + 3 + 3 = 36, odd summation.1 = Input : test_list = [345, 893, 1948, 34, 2346] Output : Odd digit sum : 36 Even digit sum : 40 Explanation : 3 + 5 + 9 + 3 + 1 + 9 + 3 + 3 = 36, odd summation.0 Input : test_list = [345, 893, 1948, 34, 2346] Output : Odd digit sum : 36 Even digit sum : 40 Explanation : 3 + 5 + 9 + 3 + 1 + 9 + 3 + 3 = 36, odd summation.4 Input : test_list = [345, 893, 1948, 34, 2346] Output : Odd digit sum : 36 Even digit sum : 40 Explanation : 3 + 5 + 9 + 3 + 1 + 9 + 3 + 3 = 36, odd summation.5 Input : test_list = [345, 893, 1948, 34, 2346] Output : Odd digit sum : 36 Even digit sum : 40 Explanation : 3 + 5 + 9 + 3 + 1 + 9 + 3 + 3 = 36, odd summation.6 Input : test_list = [345, 893, 1948, 34, 2346] Output : Odd digit sum : 36 Even digit sum : 40 Explanation : 3 + 5 + 9 + 3 + 1 + 9 + 3 + 3 = 36, odd summation.7 Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.1 Input : test_list = [345, 893, 1948, 34, 2346] Output : Odd digit sum : 36 Even digit sum : 40 Explanation : 3 + 5 + 9 + 3 + 1 + 9 + 3 + 3 = 36, odd summation.0 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.0 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.1 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.2 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.3 The original list is : [345, 893, 1948, 34, 2346] Odd digit sum : 36 Even digit sum : 409 The original list is : [345, 893, 1948, 34, 2346] Odd digit sum : 36 Even digit sum : 400 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.3 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.4 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.5 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.6 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.7 = = The original list is : [345, 893, 1948, 34, 2346] Odd digit sum : 36 Even digit sum : 402 Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.8 The original list is : [345, 893, 1948, 34, 2346] Odd digit sum : 36 Even digit sum : 404 = Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.0 The original list is : [345, 893, 1948, 34, 2346] Odd digit sum : 36 Even digit sum : 407 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.3 Odd digit sum : 36 Even digit sum : 406 Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.1 Odd digit sum : 36 Even digit sum : 408 Odd digit sum : 36 Even digit sum : 409 The original list is : [345, 893, 1948, 34, 2346] Odd digit sum : 36 Even digit sum : 409 The original list is : [345, 893, 1948, 34, 2346] Odd digit sum : 36 Even digit sum : 400 The original list is : [345, 893, 1948, 34, 2346] Odd digit sum : 36 Even digit sum : 402 Input : test_list = [345, 893, 1948, 34, 2346] Output : Odd digit sum : 36 Even digit sum : 40 Explanation : 3 + 5 + 9 + 3 + 1 + 9 + 3 + 3 = 36, odd summation.1 The original list is : [345, 893, 1948, 34, 2346] Odd digit sum : 36 Even digit sum : 404 = Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.0 The original list is : [345, 893, 1948, 34, 2346] Odd digit sum : 36 Even digit sum : 407 Các This can be easily solved using divisibility of 11. This condition is only satisfied if the number is divisible by 11. So check the number is divisible by 11 or not.
Phương pháp 2: Điều này có thể dễ dàng giải quyết bằng cách sử dụng khả năng chia rẽ 11. Điều kiện này chỉ được thỏa mãn nếu số này chia hết cho 11. Vì vậy, hãy kiểm tra số được chia cho 11 hoặc không. & NBSP;Thí dụ Python Odd digit sum : 36 Even digit sum : 407 Odd digit sum : 36 Even digit sum : 408 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.3 num 0 num 1Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.6 num 3 = = Input : test_list = [345, 893, 1948, 34, 2346] Output : Odd digit sum : 36 Even digit sum : 40 Explanation : 3 + 5 + 9 + 3 + 1 + 9 + 3 + 3 = 36, odd summation.0 Odd digit sum : 36 Even digit sum : 409 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.3 Odd digit sum : 36 Even digit sum : 406 Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.1 Odd digit sum : 36 Even digit sum : 408 Odd digit sum : 36 Even digit sum : 409 The original list is : [345, 893, 1948, 34, 2346] Odd digit sum : 36 Even digit sum : 409 The original list is : [345, 893, 1948, 34, 2346] Odd digit sum : 36 Even digit sum : 400 Input : test_list = [345, 893] Output : Odd digit sum : 20 Even digit sum : 12 Explanation : 4 + 8 = 12, even summation.3 Odd digit sum : 36 Even digit sum : 406 Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.1 Odd digit sum : 36 Even digit sum : 405 Odd digit sum : 36 Even digit sum : 409
|