Pikir dan Rasa

cogito ergo sum

Archive for September 13th, 2011

Contoh sederhana fungsi print() pada Python 3

leave a comment »

Berikut adalah contoh baris kode sederhana yang mempergunakan fungsi print() pada Python 3.


#!/usr/bin/env python
a = 10
b = 12.235123
c = 54.1315159685268134
d = 4
e = 5
f = b/c

print("")
print("Nilai a = ", a)
print("Nilai b = ", b)
print("Nilai c = ", c)
print("")
print("Nilai 4/5= ", d/e)
print("")
print("Nilai b/c= ", b/c)
print("Nilai b/c= %f" % (b/c))
print("Nilai b/c= %d" % (b/c))
print("Nilai b/c= %s" % (b/c))
print("")
print("Nilai b/c dengan format %d","= %d" % (b/c), " ,terlihat bedanya dengan f =", f)
print("")

Hasilnya sebagai berikut:

sunu@sunu-HP-Mini-110-1000:~/pythonlat$ python3 printpython3.py

Nilai a = 10
Nilai b = 12.235123
Nilai c = 54.1315159685

Nilai 4/5= 0.8

Nilai b/c= 0.226025870162
Nilai b/c= 0.226026
Nilai b/c= 0
Nilai b/c= 0.22602587016

Nilai b/c dengan format %d = 0  ,terlihat bedanya dengan f = 0.226025870162

 

Written by sunupradana

September 13, 2011 at 11:47 am

Posted in Komputer

Tagged with ,

Watch “Predicting Urban Crime? There’s an Equation for That” on YouTube

leave a comment »

Posted from WordPress for Android

Written by sunupradana

September 13, 2011 at 1:35 am

Watch “Microsoft: A Case Study in Corporate Success (And Failure)” on YouTube

leave a comment »

Posted from WordPress for Android

Written by sunupradana

September 13, 2011 at 1:25 am