-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path001-helloworld.py
More file actions
57 lines (44 loc) · 1.35 KB
/
001-helloworld.py
File metadata and controls
57 lines (44 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
A classic "Hello, World!" application in 8 different ways
---------------------------------------------------------
Update 01: * add one more method, now 8 ways are available
* correct typo
Output: (text) Print "Hello, World!" message in the console
"""
from time import sleep
# Print "Hello, World!"
print('Hello, World!')
# Print "Hello, World!" with using variable
a = 'Hello, World!'
print(a)
# Print "Hello, World!" with using an empty variable and adding the text later
a = ''
a += 'Hello, World!'
print(a)
# Print "Hello, World!" with formatting
a = 'Hello,'
b = ' World!'
print('{}{}'.format(a,b))
# Print "Hello, World!" with formatting and adding punctuation in the print()
a = 'Hello'
b = 'World'
print('{}, {}!'.format(a,b))
# Print "Hello, World!" with formatting and capitalizing
a = 'hello'
a = a.capitalize()
b = 'world'
c = b.capitalize()
print('{}, {}!'.format(a,c))
# Print "Hello, World!" with for loop iterate over list
letters = ['H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!']
message = ''
for i in letters:
message += i
print(message)
# Print "Hello, World!" with for loop iterate over string
original_message = 'Hello, World!'
message = ''
for i in original_message:
message += i
sleep(0.2)
print('\r{}'.format(message), end='')