Operator Divisi ing Python

Pambuka

Upaminipun kita duwe 12 mangga lan kita kudu merata mbagekke kanggo 3 anak. Dadi, kepiye carane nemtokake jumlah pelem sing kudu diwenehake supaya saben wong entuk pelem sing padha? Kanggo iki, kita bisa nggunakake operator divisi.

Nalika nindakake divisi ing angka, kita bisa nyana output minangka nomer floating-titik sing tepat utawa output minangka nilai integer sing dibunderaké.

Operator divisi Python ana rong jinis:

  • / : Dibagi loro nomer lan ngasilake nilai ngambang.
  • // : Dibagi nomer loro lan ngasilake nilai lantai.

program

1. Operator divisi(/)

print("Bagi integer kanthi integer") print("4/2 = ", 4/2) print("15/5 = ", 15/5) print("-4/2 = ", -4/2) print("-15/5 = ", -15/5) print(" ") print("Bagi float kanthi integer") print("4.2/2 = ", 4.2/2) print("15.7/5 = " , 15.7/5) print("-4.2/2 = ", -4.2/2) print("-15.7/5 = ", -15.7/5) print("") print("Bagi integer kanthi float") print ("4/2.2 = ", 4/2.2) print("15/5.1 = ", 15/5.1) print("-4/2.2 = ", -4/2.2) print("-15/5.1 = ", -15/5.1) print(" ") print("Dibagi float kanthi float") print("4.6/2.5 = ", 4.6/2.5) print("15.5/5.5 = ", 15.5/5.5) print("-4.6 /2.5 = ", -4.6/2.5) print("-15.5/5.5 = ", 1-5.5/5.5) print("")

Output:

Operator Divisi ing Output Python 1

2. Operator divisi lantai(//)

 

print("Bagi integer kanthi integer") print("4//2 = ", 4//2) print("15//5 = ", 15//5) print("-4//2 = ", -4//2) print("-15//5 = ", -15//5) print(" ") print("Divide float by integer") print("4.2//2 = ", 4.2// 2) print("15.7//5 = ", 15.7//5) print("-4.2//2 = ", -4.2//2) print("-15.7//5 = ", -15.7//5 ) print("") print("Bagi integer kanthi float") print("4//2.2 = ", 4/2.2) print("15/5.1 = ", 15/5.1) print("-4 //2.2 = ", -4//2.2) print("-15//5.1 = ", -15//5.1) print(" ") print("Dibagi float dengan float") print("4.6/2.5 = ", 4.6//2.5) print("15.5//5.5 = ", 15.5//5.5) print("-4.6//2.5 = ", -4.6//2.5) print("-15.5//5.5 = " , -15.5/5.5) print("")

 

Output:

Operator Divisi ing Output Python 2

Saka output saka rong program kasebut, kita bisa mirsani manawa operator divisi (/) mbagi nilai lan ngasilake output minangka nomer floating point, dene operator divisi lantai (//) pisanan mbagi nilai kasebut banjur dibunderaké dadi output. Nilai lantai sadurunge ditampilake.

Pengarang


komentar

Ninggalake a Reply

Panjenengan alamat email ora bisa diterbitake. Perangkat kothak ditandhani *

Situs iki nggunakake Akismet kanggo ngurangi spam. Sinau babagan proses data sampeyan.