w1 Basic Algorithm-40275

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Algoritma dan Pemrograman

Komputer
01-Basic Algorithm

2/14/2020 1
What is Python?
Is it dangerous?
What is Python

Python is an incredibly efficient language: The programs will do more in fewer lines of code than many other
languages would require. Python’s syntax will also help write “clean” code.

The perks of Python (Matthes, 2015)

Easy to
Easy to Read Easy to Debug
Extend

IEH2B3 | Algoritma dan Pemrograman Komputer 3


Purpose of Python?

Developing Game Web Apps

IEH2B3 | Algoritma dan Pemrograman Komputer 4


Get Started!

print(“Hello I’m learning Python”) The text in bold is what you’ll type in and then execute by
pressing “Enter:
Hello I’m learning Python

This called Variable, every variable hold a value

This called String, and it is a series of characters


message = “Hello I’m learning Python”
print(message)
Hello I’m learning Python

IEH2B3 | Algoritma dan Pemrograman Komputer 5


Get Started
• Variable names can contain only letters, numbers, and
underscores.They can start with a letter or an underscore,
but not with a number.For instance, you can call a variable
message_1 but not 1_message.
• Spaces are not allowed in variable names, but underscores
can be used to separate words in variable names. For
example, greeting_message works, but greeting message
The Rules of will cause errors.
Naming a value • Avoid using Python keywords and function names as
variable names; that is, do not use words that Python has
reserved for a particular programmatic purpose, such as
the word print.
• Variable names should be short but descriptive. For
example, name is better than n, student_name is better
than s_n, and name_length is better than
length_of_persons_name.
• Be careful when using the lowercase letter l and the
uppercase letter O. Because they could be confused with
the numbers 1 and 0.

IEH2B3 | Algoritma dan Pemrograman Komputer 6


Try This!

message = “Hello I’m learning Python” Python Dictionary Series


massage = ‘This is the second massage’
.title = To make first letter of each words Upper
sausage = message+” “+massage
.upper = to make all words in uppercase
print(message.upper())
.lower = to make all words in lowercase
print(sausage)
.rstrip = to remove whitespace from right
.lstrip = to remove whitespace from left
.strip = to remove whitespace from both sides

first_message = “ Hello I’m learning Python ”


second_message = “\tThis is the indentation tab”
combine= first_message.strip()+” ”+second_message
print(combine)

IEH2B3 | Algoritma dan Pemrograman Komputer 7


Basic Operation
Python can compute simple mathematics expression

2+3 3 **2
5 9

3–2
1

2*3
6

3/2
1.5

IEH2B3 | Algoritma dan Pemrograman Komputer 8


How to Comment?

# this is the comment, not on the net tv of course *LOL


print(“Hello Python People! All Rise!”)

Hello Python People! All Rise!

IEH2B3 | Algoritma dan Pemrograman Komputer 9


Time Out!

In Python create the following output:


Line 1 Einstein Said:
Line 2 “The true sign of intelligence is not
Line 3 knowledge but imagination”
Line 4
Line 5 So can you imagine if 5 + 5 = 10
Line 6 Then 15 Mod 4 equal?
Line 7
Line 8 (print the answer for line 6 here)

IEH2B3 | Algoritma dan Pemrograman Komputer 10

You might also like