-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04userinput.py
More file actions
32 lines (22 loc) · 868 Bytes
/
04userinput.py
File metadata and controls
32 lines (22 loc) · 868 Bytes
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
# we will learn how to accept user input,
# and we will have some exercises: mad libs, area calc, and shopping cart
# to accept some user input, we can use input() function
# input(prompt: object = "", /) -> str
# input("Enter your name: ")
# kode ini akan menerima input, akan tetapi,
# kita perlu variabel untuk menampung input yang masuk
name = input("Enter your name: ")
# age = input("Enter your age: ")
# age = int(age)
# with one line, casting to int:
age = int(input("Enter your age: "))
# casting to float
# age = float(input("Enter your age: "))
# kita coba jumlahkan age
age = age + 1
print(f"Hello, {name}")
print(f"You are {age} years old.")
# perlu diingat, setiap kita menerima input dari user,
# input itu selalu bertipe string,
# jadi saat input yang dimasukkan user akan digunakan untuk keperluan perhitungan,
# perlu dilakukan typecasting