Để có được chữ số cuối cùng của một số trong Python: Ví dụ: hãy để Lừa nhận được chữ số cuối cùng của số 162329:162329: Output: Bạn cũng có thể làm cho mã trên ngắn hơn một chút bằng cách kết hợp các bước 1-3 thành một biểu thức duy nhất: Kết quả: Cách tiếp cận tương tự bạn đã học trước đó cũng hoạt động cho các số thập phân. Để có được chữ số cuối cùng của một số thập phân, hãy chuyển đổi số thành một chuỗi, lấy ký tự cuối cùng và chuyển đổi nó trở lại một số nguyên. Ví dụ, hãy để Lừa nhận được số thập phân cuối cùng của một xấp xỉ ba thập phân của PI. Output: Hôm nay bạn đã học được cách lấy số cuối cùng từ một chữ số. Để tóm tắt lại, lấy biểu diễn chuỗi của số, truy cập ký tự cuối cùng và chuyển đổi nó trở lại sang số nguyên. Cảm ơn vì đã đọc. Mã hóa hạnh phúc! Thủ thuật Python Cách ghi vào một tệp trong Python Với tuyên bố trong Pythonn = 162329
# 1. Get the string representation
num_str = repr[n]
# 2. Access the last string of the digit string:
last_digit_str = num_str[-1]
# 3. Convert the last digit string to an integer:
last_digit = int[last_digit_str]
print[f"The last digit of {n} is {last_digit}"]
The last digit of 162329 is 9
Cách tiếp cận tốc ký
n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
The last digit of 162329 is 9
pi = 3.141
last_digit = int[repr[pi][-1]]
print[f"The last digit of {pi} is {last_digit}"]
The last digit of 3.141 is 1
Sự kết luận
Đọc thêm
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 132
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]16
The last digit of 162329 is 92
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
5str = "abcdefgh"
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]23
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 143
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 146
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]48
The last digit of 162329 is 98
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 150
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]8
The last digit of 3.141 is 152
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]54
The last digit of 162329 is 92
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 156
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]58
The last digit of 3.141 is 132
Output:
"efgh"
The last digit of 3.141 is 1
5 pi = 3.141
last_digit = int[repr[pi][-1]]
print[f"The last digit of {pi} is {last_digit}"]
10
The last digit of 162329 is 9
21 The last digit of 162329 is 9
22
n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
2pi = 3.141
last_digit = int[repr[pi][-1]]
print[f"The last digit of {pi} is {last_digit}"]
14The last digit of 162329 is 9
26 n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
23The last digit of 162329 is 9
7pi = 3.141
last_digit = int[repr[pi][-1]]
print[f"The last digit of {pi} is {last_digit}"]
18
The last digit of 162329 is 921
The last digit of 162329 is 941
The last digit of 3.141 is 1
5 pi = 3.141
last_digit = int[repr[pi][-1]]
print[f"The last digit of {pi} is {last_digit}"]
10
Cải thiện bài viết
Lưu bài viết
Đưa ra một số và để tìm chữ số đầu tiên và cuối cùng của một số.examples: & nbsp; & nbsp;
Examples:
Input : 12345 Output : First digit: 1 last digit : 5 Input : 98562 Output : First digit: 9 last digit : 2
Để tìm chữ số cuối cùng của một số, chúng tôi sử dụng toán tử modulo %. Khi modulo chia cho 10 trả về chữ số cuối cùng của nó. Để tìm chữ số đầu tiên của một số, chúng tôi chia số đã cho 10 cho đến khi số lớn hơn 10. Ở cuối, chúng tôi còn lại với chữ số đầu tiên. & NBSP;modulo operator %. When modulo divided by 10 returns its last digit.
Suppose if n = 1234
then last Digit = n % 10 => 4
To finding first digit of a number is little expensive than last digit. To find first digit of a number we divide the given number by 10 until number is greater than 10. At the end we are left with the first digit.
Cách tiếp cận 1 [với vòng lặp]:
C++
The last digit of 162329 is 93
The last digit of 162329 is 94
The last digit of 162329 is 95
The last digit of 162329 is 96
The last digit of 162329 is 97
The last digit of 162329 is 98
The last digit of 162329 is 97
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]0
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]3
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]4
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]6
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]9
The last digit of 162329 is 90
The last digit of 162329 is 97
The last digit of 162329 is 92
The last digit of 162329 is 97
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]0
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 162329 is 98
The last digit of 162329 is 90
The last digit of 162329 is 97
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 97
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]7
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 3.141 is 10
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 3.141 is 13
The last digit of 162329 is 90
Java
The last digit of 3.141 is 15
The last digit of 3.141 is 16
The last digit of 3.141 is 15
The last digit of 3.141 is 18
The last digit of 3.141 is 19
str = "abcdefgh"
0 str = "abcdefgh"
1n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 19
str = "abcdefgh"
4 The last digit of 162329 is 97
The last digit of 162329 is 98
The last digit of 162329 is 97
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]0
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]3
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
3str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
5str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
6str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
7str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
9n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]9
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 19
str = "abcdefgh"
4 The last digit of 162329 is 97
The last digit of 162329 is 92
The last digit of 162329 is 97
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]0
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
Input : 12345 Output : First digit: 1 last digit : 5 Input : 98562 Output : First digit: 9 last digit : 26
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4Input : 12345 Output : First digit: 1 last digit : 5 Input : 98562 Output : First digit: 9 last digit : 28
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 19
str = "abcdefgh"
4 The last digit of 162329 is 904
The last digit of 162329 is 905
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 97
The last digit of 162329 is 910
The last digit of 162329 is 911
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
9n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 914
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 917
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
The last digit of 162329 is 90
Python3
The last digit of 162329 is 921
The last digit of 162329 is 922
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]3
The last digit of 162329 is 925
The last digit of 162329 is 926
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4The last digit of 162329 is 928
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 930
The last digit of 162329 is 926
The last digit of 162329 is 930
The last digit of 162329 is 933
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
9n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 162329 is 97
The last digit of 162329 is 939
The last digit of 162329 is 921
The last digit of 162329 is 941
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 162329 is 944
The last digit of 162329 is 945
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4The last digit of 162329 is 947
The last digit of 162329 is 930
The last digit of 162329 is 926
The last digit of 162329 is 911
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
9The last digit of 162329 is 952
The last digit of 162329 is 953
The last digit of 162329 is 926
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]8
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
5The last digit of 162329 is 952
The last digit of 162329 is 958
C#
The last digit of 162329 is 94
The last digit of 162329 is 960
The last digit of 3.141 is 19
str = "abcdefgh"
0 str = "abcdefgh"
1n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 19
str = "abcdefgh"
4 The last digit of 162329 is 97
The last digit of 162329 is 98
The last digit of 162329 is 97
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]0
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]3
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
3str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
5str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
6n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]6
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]9
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 19
str = "abcdefgh"
4 The last digit of 162329 is 97
The last digit of 162329 is 92
The last digit of 162329 is 97
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]0
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
Input : 12345 Output : First digit: 1 last digit : 5 Input : 98562 Output : First digit: 9 last digit : 26
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4Input : 12345 Output : First digit: 1 last digit : 5 Input : 98562 Output : First digit: 9 last digit : 28
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 19
str = "abcdefgh"
4 The last digit of 162329 is 904
The last digit of 162329 is 905
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 97
The last digit of 162329 is 910
The last digit of 162329 is 911
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
9n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]08
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 917
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
The last digit of 162329 is 90
The last digit of 162329 is 9
21 The last digit of 162329 is 9
22
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]15
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]3
The last digit of 162329 is 925
The last digit of 162329 is 926
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4The last digit of 162329 is 928
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 930
The last digit of 162329 is 926
The last digit of 162329 is 930
The last digit of 162329 is 933
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
9
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 162329 is 97
The last digit of 162329 is 939
The last digit of 162329 is 921
The last digit of 162329 is 941
The last digit of 162329 is 90
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 162329 is 944
The last digit of 162329 is 945
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4The last digit of 162329 is 947
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
The last digit of 162329 is 930
The last digit of 162329 is 926
The last digit of 162329 is 911
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
9The last digit of 162329 is 90
The last digit of 162329 is 952
The last digit of 162329 is 953
The last digit of 162329 is 926
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]8
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
5The last digit of 162329 is 94
The last digit of 162329 is 960
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]54
The last digit of 162329 is 92
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]51
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]58
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
9n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
5n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
3 n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
4
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]60
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 162329 is 98
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 19
str = "abcdefgh"
4 The last digit of 162329 is 904
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]01
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
6n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]6
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 97
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
PHP
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]16
The last digit of 162329 is 98
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 162329 is 947
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]86
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]87
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]89
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 917
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]93
n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
2n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
3 n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
23n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
18 n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
25 O[log10n]
Auxiliary Space: O[1]
n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
5n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
18 n = 162329
last_digit = int[repr[n][-1]]
print[f"The last digit of {n} is {last_digit}"]
28
C++
The last digit of 162329 is 93
The last digit of 162329 is 94
The last digit of 162329 is 95
The last digit of 162329 is 96
The last digit of 162329 is 97
The last digit of 162329 is 98
The last digit of 162329 is 97
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]0
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]3
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]4
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 911
The last digit of 162329 is 97
The last digit of 162329 is 913
The last digit of 162329 is 914
The last digit of 162329 is 915
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]9
The last digit of 162329 is 90
The last digit of 162329 is 97
The last digit of 162329 is 92
The last digit of 162329 is 97
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]0
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 162329 is 98
The last digit of 162329 is 90
The last digit of 162329 is 97
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 97
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 3.141 is 13
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]86
The last digit of 3.141 is 10
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 3.141 is 13
The last digit of 162329 is 90
Java
The last digit of 3.141 is 15
The last digit of 3.141 is 16
The last digit of 3.141 is 15
The last digit of 3.141 is 18
The last digit of 3.141 is 19
str = "abcdefgh"
0 str = "abcdefgh"
1n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 19
str = "abcdefgh"
4 The last digit of 162329 is 97
The last digit of 162329 is 98
The last digit of 162329 is 97
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]0
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 911
The last digit of 162329 is 97
The last digit of 162329 is 964
The last digit of 162329 is 97
The last digit of 162329 is 966
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4The last digit of 162329 is 968
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]9
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 19
str = "abcdefgh"
4 The last digit of 162329 is 97
The last digit of 162329 is 92
The last digit of 162329 is 97
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]0
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
Input : 12345 Output : First digit: 1 last digit : 5 Input : 98562 Output : First digit: 9 last digit : 26
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4Input : 12345 Output : First digit: 1 last digit : 5 Input : 98562 Output : First digit: 9 last digit : 28
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 19
str = "abcdefgh"
4 The last digit of 162329 is 904
The last digit of 162329 is 993
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 97
The last digit of 162329 is 910
The last digit of 162329 is 911
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
9n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]02
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]03
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]8
The last digit of 162329 is 917
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
The last digit of 162329 is 90
Python3
The last digit of 3.141 is 15
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]10
The last digit of 162329 is 921
The last digit of 162329 is 922
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]14
The last digit of 162329 is 926
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]23
The last digit of 162329 is 97
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]18
Các
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]9
The last digit of 162329 is 921
The last digit of 162329 is 941
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 162329 is 944
The last digit of 162329 is 945
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4The last digit of 162329 is 947
The last digit of 162329 is 930
The last digit of 162329 is 926
The last digit of 162329 is 911
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
9The last digit of 162329 is 952
The last digit of 162329 is 953
The last digit of 162329 is 926
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]8
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
5The last digit of 162329 is 952
The last digit of 162329 is 958
C#
The last digit of 162329 is 94
The last digit of 162329 is 960
str = "abcdefgh"
0 The last digit of 162329 is 947
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
str = "abcdefgh"
4 The last digit of 162329 is 97
The last digit of 162329 is 98
The last digit of 162329 is 97
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]0
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 97
The last digit of 162329 is 905
The last digit of 162329 is 97
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]68
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 911
The last digit of 162329 is 97
The last digit of 162329 is 964
The last digit of 162329 is 97
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]74
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]9
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
str = "abcdefgh"
4 The last digit of 162329 is 97
The last digit of 162329 is 92
The last digit of 162329 is 97
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]0
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 162329 is 98
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 19
str = "abcdefgh"
4 The last digit of 162329 is 904
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]01
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 162329 is 97
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]5
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]5
The last digit of 3.141 is 104
The last digit of 3.141 is 105
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]8
The last digit of 162329 is 917
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 162329 is 90
The last digit of 162329 is 90
PHP
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]15
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]16
The last digit of 162329 is 98
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
5The last digit of 3.141 is 116
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 118
The last digit of 3.141 is 119
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 121
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 124
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 126
The last digit of 3.141 is 118
The last digit of 3.141 is 128
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 132
The last digit of 3.141 is 133
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]16
The last digit of 162329 is 92
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
5The last digit of 3.141 is 116
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]23
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 143
The last digit of 3.141 is 133
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 146
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]48
The last digit of 162329 is 98
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 150
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]8
The last digit of 3.141 is 152
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]54
The last digit of 162329 is 92
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]18
The last digit of 3.141 is 156
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]58
The last digit of 3.141 is 132
The last digit of 3.141 is 159
JavaScript
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]60
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]16
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]63
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]1
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 165
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
The last digit of 3.141 is 167
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]9
The last digit of 162329 is 90
The last digit of 162329 is 921
The last digit of 162329 is 941
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]2
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]8
The last digit of 162329 is 944
The last digit of 162329 is 945
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
4The last digit of 162329 is 947
The last digit of 162329 is 90
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]87
The last digit of 3.141 is 179
pi = 3.141 last_digit = int[repr[pi][-1]] print[f"The last digit of {pi} is {last_digit}"]8
str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
5The last digit of 3.141 is 182
The last digit of 3.141 is 183
The last digit of 162329 is 947
n = 162329 last_digit = int[repr[n][-1]] print[f"The last digit of {n} is {last_digit}"]93
The last digit of 162329 is 9
30The last digit of 162329 is 9
26 The last digit of 162329 is 9
11
9O[1]str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]
Auxiliary Space: O[1]
The last digit of 162329 is 9
52The last digit of 162329 is 9
53The last digit of 162329 is 9
26 pi = 3.141
last_digit = int[repr[pi][-1]]
print[f"The last digit of {pi} is {last_digit}"]
8
5log10[] is a mathematical function present in math.h header file. It returns log base 10 value of the passed parameter to log10[] function. str = "abcdefgh"
lastFour = str[-4:]
print[lastFour]