Branching in Python

Hi, This time i want to share How to create branching using the Python language, immediately wrote i love examples of Branching easily so that you can learn it.

Determining Even & Odd Numbers

n = int(input("n :"))
if(n%2==1) :
        print('ganjil')
else :
        print('genap')

Explanation on program example above:

Creating a branching, you just need to type in the editor or IDLE python Pycharm you.

VARIABEL --> n
INPUT BILANGAN --> int(input("n :"))
ASUMSI JIKA GANJIL --> if(n%2==1) :
        print('ganjil')
ASUMSI JIKA GENAP --> else :
        print('genap')
OUTPUT --> print()

Determine the Value of Students

n = int(input("nilai :"))
if (n>80) :
    hasil="A"
elif (n>60) and (n<=80) :
    hasil="B"
elif (n>50) and (n<=60) :
    hasil="C"
else :
    hasil="D"
print(hasil)

Explanation on program example above:

Creating a branching, you just need to type in the editor or IDLE python Pycharm you.

VARIABEL --> n
INPUT BILANGAN --> int(input("nilai :"))
ASUMSI JIKA MENDAPAT A --> if (n>80) :
    hasil="A"
ASUMSI JIKA TIDAK MENDAPAT A TETAPI DAPAT B --> elif (n>60) and (n<=80) :
    hasil="B"
ASUMSI JIKA TIDAK MENDAPAT B TETAPI DAPAT C -->elif (n>50) and (n<=60) :
    hasil="C"
ASUMSI JIKA MENDAPAT D --> else :
    hasil="D"
OUTPUT --> print(hasil)

Determining the Age Restriction to obtain a driving license

umur = int(input("umur : "))
nilaites = int(input("nilaites : "))
if umur > 17:
    if nilaites > 80:
        hasil = ("Selamat anda berhak mendapatkan SIM")
    else:
        hasil = ("Maaf anda tidak berhak mendapatkan SIM, Nilai test anda kurang")
elif umur == 17:
    if nilaites > 80:
        hasil = ("Maaf anda tidak berhak mendapatkan SIM, umur anda belum mencukupi")
    elif nilaites < 80:
        hasil = ("Maaf anda tidak berhak mendapatkan SIM, umur dan nilai belum mencukupi")
elif umur < 17:
    if nilaites < 80:
        hasil = ("maaf anda tidak lulus karena nilai dan umur tidak mencukupi")
print(hasil)

Determining the value of SIM Test

umur = int(input("umur :"))
nilai = int(input("nilai tes :"))
if (umur>17) :
    if (nilai>80):
            hasil=("Selamat")
    else :
            hasil=("Maaf")
else :
    hasil=("GAGAL")
print(hasil)

Explanation on program example above:

Creating a branching, you just need to type in the editor or IDLE python Pycharm you.

VARIABEL --> umur, nilai, hasil
INPUT BILANGAN --> int(input("umur :"))
JIKA BERUMUR 17 & MENDAPAT NILAI 80 --> if (umur>17) :
    if (nilai>80):
            hasil=("Selamat")
    else :
            hasil=("Maaf")
JIKA DIBAWAH 17 DAN NILAI DIBAWAH 80 --> else :
    hasil=("GAGAL")
OUTPUT --> print(hasil)

Source Code?

You guys please check on this site:

– https://github.com/poncoe/python_basic/tree/master/bab2_if-else
– https://github.com/poncoe/python_basic

Post Author: Study