You are on page 1of 6

1/25/22, 12:31 PM Babas Phyton Excercise.

ipynb - Colaboratory

print("Hello World")

Hello World

Part 2. Python Basics

nama = "Babas"
semester = 4

print(10+5);print(3**20);print((5+8)*4/7);print(5+8*4/7)
print(nama)
print (semester)

a = 15
b = 50
c = b-a
print(c)

15

3486784401

7.428571428571429

9.571428571428571

Babas

35

a = "hello world"
a = 10+5

print(a)

15

Code For Asking Input

tanyanama = input("Write Your Name: ")
tanyausia = input("How Old Are You: ")
print(tanyanama)
print(tanyausia)

Write Your Name: babas

How Old Are You: 26

babas

26

nama = input("Write Down Your Name: ")

print("Guten Tag ", nama, ". Bitte Schon")

https://colab.research.google.com/drive/1wRRn1sWmbZBG7gD_sGOjZQbWx1VbE3cn#scrollTo=RSPek717-XnJ&printMode=true 1/6
1/25/22, 12:31 PM Babas Phyton Excercise.ipynb - Colaboratory

Write Down Your Name: babas

Guten Tag babas . Bitte Schon

salam = "Halo Dunia"

nomor = "80"

cek = isinstance(nomor,str)

print(cek)

True

salam pada akhirnya variabel bertipe data string karena ada tanda kutip ganda "xx"

sahabat = "babas"

usia = 27

print(f'How are you {sahabat} Your Age Is {usia}')

How are you babas Your Age Is 27

String Continantion

text1 = "how are you?."

text2 = "I'm fine"

complete = text1 + text2

print(complete)

how are you?.I'm fine

Asterisk Operation (*), meaning repeatition

text1 = "how are you?."
text2 = "I'm fine"
complete = text1 + text2

text3 = "+"*2

print(text3)

++

Works with number

number1 = 7

number2 = 6

circle = number1 * number2 * number2

https://colab.research.google.com/drive/1wRRn1sWmbZBG7gD_sGOjZQbWx1VbE3cn#scrollTo=RSPek717-XnJ&printMode=true 2/6
1/25/22, 12:31 PM Babas Phyton Excercise.ipynb - Colaboratory

print(circle)

type(circle)

252

int

Angka Dalam Phyton :

1. Bulat (integer) ex : 1,2,...


2. Pecahan (float) ex : 1.2,1.5,...
3. Complex ex : 10+8j

Works with function int() and float()

int()

tanyanilai = input("Write Your value: ")

tanyanilai = int(tanyanilai)

print(tanyanilai + 5)

type(tanyanilai)

Write Your value: 5

10

int

dengan menggunakan fungsi variable input print, hasilnya dianggap sebagai string, jadi tidak
bisa dilakukan operasi matematika, jadi harus dilakukan konversi tipe data dari string menjadi
integer

float()

tanyanilai = input("Write Your value: ")

tanyanilai = float(tanyanilai)

print(tanyanilai + 5)

type(tanyanilai)

Write Your value: 4

9.0

float

Excercise fungsi int() dan float()

int()

https://colab.research.google.com/drive/1wRRn1sWmbZBG7gD_sGOjZQbWx1VbE3cn#scrollTo=RSPek717-XnJ&printMode=true 3/6
1/25/22, 12:31 PM Babas Phyton Excercise.ipynb - Colaboratory

number = input("How Big You Are: ")

total = int(number) + 7

print("Jumlah: ",total)
type(total)

How Big You Are: 44

Jumlah: 51

int

float()

number = input("How Big You Are: ")

total = float(number) + 7

print("Jumlah: ",total)
type(total)

How Big You Are: 44

Jumlah: 51.0

float

User Input : Menghitung Luas Lingkaran

 radius = input("Input the radius value in ft: ")

 radius = float(radius)
 phi = 3.14

 circlearea = phi * radius * radius

 print(circlearea)

 type(circlearea)

Input the radius value in ft: 7

153.86

float

 radius = input("Input the radius value in ft: ")

 radius = float(radius)
 phi = 3.14

 circlearea = phi * radius * radius

 print(f'Circle Area with {radius} ft is {circlearea} ft2')

 type(circlearea) 

Input the radius value in ft: 4

Circle Area with 4.0 ft is 50.24 ft2

float

memanfaatkan parameter f' untuk memanfaatkan nilai syntax {circlearea}

print("x"*50)

print("Write Down Your Name")

https://colab.research.google.com/drive/1wRRn1sWmbZBG7gD_sGOjZQbWx1VbE3cn#scrollTo=RSPek717-XnJ&printMode=true 4/6
1/25/22, 12:31 PM Babas Phyton Excercise.ipynb - Colaboratory

print("x"*50)

name = input("Write Down Your Name: ")

radius = input("Input Your Radius in ft: ")

radius = float(radius)

phi = 3.14

circlearea = phi * radius * radius

print("x"*50)

print("Hi!! Here is your circle area, ", name)

print("Circle Area = ", circlearea)

print("*"*50)

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Write Down Your Name

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Write Down Your Name: babas

Input Your Radius in ft: 45

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Hi!! Here is your circle area, babas

Circle Area = 6358.500000000001

**************************************************

identity operator

value1 = 10

value2 = 10

value3 = 30

print(value1 is value2)
print(value3 is not value2)

True

True

identity operator, sebagai pembanding atau sebagai identifier jenis datanya apakah sama atau
tidak

https://colab.research.google.com/drive/1wRRn1sWmbZBG7gD_sGOjZQbWx1VbE3cn#scrollTo=RSPek717-XnJ&printMode=true 5/6
1/25/22, 12:31 PM Babas Phyton Excercise.ipynb - Colaboratory

https://colab.research.google.com/drive/1wRRn1sWmbZBG7gD_sGOjZQbWx1VbE3cn#scrollTo=RSPek717-XnJ&printMode=true 6/6

You might also like