Làm thế nào để bạn đọc một số có 4 chữ số trong python?

Để lấy 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 lại thành số nguyên

Ví dụ: hãy lấy số thập phân cuối cùng của xấp xỉ ba số thập phân của Pi

pi = 3.141
last_digit = int[repr[pi][-1]]

print[f"The last digit of {pi} is {last_digit}"]

đầu ra

The last digit of 3.141 is 1

Sự kết luận

Hôm nay bạn đã học cách lấy số cuối cùng từ một chữ số

Tóm 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 số nguyên

9 2
5
9 2
61
9 2
57
9 2
89
9 2
0
The last digit of 3.141 is 1
3062
9 2
64
The last digit of 3.141 is 1
3116
9 2
89
The last digit of 3.141 is 1
327
The last digit of 3.141 is 1
3067

 

9 2
5____13069

9 2
5
9 2
8
9 2
9

 

9 2
74

9 2
48
9 2
76

9 2
5

9 2
5
9 2
78

9 2
5
9 2
8
9 2
81
9 2
82
The last digit of 3.141 is 1
327
The last digit of 3.141 is 1
328

 

9 2
85

9 2
61
9 2
57
9 2
34
The last digit of 3.141 is 1
372

9 2
90____291____257
The last digit of 3.141 is 1
302
The last digit of 3.141 is 1
328

9 2
90____296

 

9 2
97

C#




The last digit of 3.141 is 1
3098

The last digit of 3.141 is 1
3099

The last digit of 3.141 is 1
42
9 2
01

 

The last digit of 3.141 is 1
426
The last digit of 3.141 is 1
3157

9 2
5

9 2
5
The last digit of 3.141 is 1
37

9 2
5
The last digit of 3.141 is 1
463
9 2
0
9 2
1
9 2
0
9 2
3

9 2
5
9 2
4

9 2
2____13102

9 2
2
9 2
0
The last digit of 3.141 is 1
3105____20
The last digit of 3.141 is 1
4221

9 2
5

9 2
2____13111

9 2
2______13113
9 2
0
The last digit of 3.141 is 1
3182
9 2
0
The last digit of 3.141 is 1
4230

9 2
5

9 2
2____13119

9 2
2____28
9 2
9

9 2
5
The last digit of 3.141 is 1
550

9 2
5

9 2
5
The last digit of 3.141 is 1
551

9 2
5
The last digit of 3.141 is 1
463
9 2
0
The last digit of 3.141 is 1
553
9 2
0
9 2
3

9 2
5
9 2
4

9 2
2____1558

9 2
2____28
The last digit of 3.141 is 1
311

9 2
5
The last digit of 3.141 is 1
550

9 2
5

9 2
5
The last digit of 3.141 is 1
313

9 2
5
The last digit of 3.141 is 1
425
The last digit of 3.141 is 1
463
9 2
27
9 2
59

9 2
5
9 2
4

9 2
2____20
The last digit of 3.141 is 1
319

9 2
2____266

The last digit of 3.141 is 1
4272
The last digit of 3.141 is 1
302
9 2
40

9 2
5
The last digit of 3.141 is 1
550

The last digit of 3.141 is 1
550

 

 

The last digit of 3.141 is 1
4278

PHP




9 2
74

The last digit of 3.141 is 1
55

The last digit of 3.141 is 1
31

 

The last digit of 3.141 is 1
37

9 2
78
9 2
1____280
The last digit of 3.141 is 1
328

9 2
4

9 2
5
The last digit of 3.141 is 1
3102

9 2
5
The last digit of 3.141 is 1
4291
The last digit of 3.141 is 1
4292
9 2
80
9 2
18

 

9 2
5
The last digit of 3.141 is 1
3111

9 2
5
9 2
80
The last digit of 3.141 is 1
4299
9 2
80
The last digit of 3.141 is 1
4601
The last digit of 3.141 is 1
4291
The last digit of 3.141 is 1
4603

 

9 2
5____13119

9 2
5
9 2
8
9 2
80
The last digit of 3.141 is 1
372

The last digit of 3.141 is 1
550

 

The last digit of 3.141 is 1
551

9 2
78
The last digit of 3.141 is 1
553____280
The last digit of 3.141 is 1
328

9 2
4

9 2
5
The last digit of 3.141 is 1
558

9 2
5
9 2
8
9 2
89
9 2
80
The last digit of 3.141 is 1
5516

The last digit of 3.141 is 1
550

 

The last digit of 3.141 is 1
5518

9 2
80
The last digit of 3.141 is 1
5520

The last digit of 3.141 is 1
5521
9 2
1____280
The last digit of 3.141 is 1
4631
The last digit of 3.141 is 1
302
The last digit of 3.141 is 1
4633

The last digit of 3.141 is 1
5527
The last digit of 3.141 is 1
553
9 2
80____14637
The last digit of 3.141 is 1
5531
The last digit of 3.141 is 1
372

 

The last digit of 3.141 is 1
4640

The last digit of 3.141 is 1
4641

Javascript




The last digit of 3.141 is 1
5535

 

The last digit of 3.141 is 1
4643

9 2
76

 

The last digit of 3.141 is 1
37

9 2
78
The last digit of 3.141 is 1
5542

9 2
4

9 2
5

9 2
5
The last digit of 3.141 is 1
3102

9 2
5
The last digit of 3.141 is 1
4653

 

9 2
5
The last digit of 3.141 is 1
3111

9 2
5
The last digit of 3.141 is 1
4657

 

9 2
5____13119

9 2
5
9 2
8
9 2
9

The last digit of 3.141 is 1
550

 

The last digit of 3.141 is 1
551

9 2
78
The last digit of 3.141 is 1
4666

9 2
5

9 2
5
The last digit of 3.141 is 1
558

9 2
5
9 2
8
The last digit of 3.141 is 1
4672

The last digit of 3.141 is 1
550

 

The last digit of 3.141 is 1
5518

The last digit of 3.141 is 1
5579

_______14676____1302____1328

The last digit of 3.141 is 1
4679
The last digit of 3.141 is 1
4680
The last digit of 3.141 is 1
328

 

The last digit of 3.141 is 1
4682

 

The last digit of 3.141 is 1
5588

Đầu ra

9 2

Độ phức tạp về thời gian. O[1]
Không gian phụ. Ô[1]

Lưu ý quan trọng. log10[] là một hàm toán học có trong toán học. tập tin tiêu đề h. Nó trả về giá trị nhật ký cơ sở 10 của tham số đã truyền cho hàm log10[].  

Chủ Đề