Pikir dan Rasa

cogito ergo sum

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 ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: