จงเขียนโปรแกรมรับชื่อจากผู้ใช้ แล้วแสดงข้อความว่า
Hello, [ชื่อ]!
🧠 ตัวอย่างการทำงาน:
Enter your name: Alice
Hello, Alice!
<details> <summary>เฉลย</summary>
name = input("Enter your name: ")
print("Hello,", name + "!")
</details>
จงเขียนโปรแกรมรับอายุ แล้วแสดงข้อความว่า
You are [อายุ] years old.
<details> <summary>เฉลย</summary>
age = input("How old are you? ")
print("You are", age, "years old.")
</details>
รับตัวเลข 2 ตัวจากผู้ใช้ แล้วแสดงผลรวมของทั้งสองตัวเลข
🧠 ตัวอย่างการทำงาน:
Enter number 1: 5
Enter number 2: 8
Sum is: 13
<details> <summary>เฉลย</summary>
num1 = int(input("Enter number 1: "))
num2 = int(input("Enter number 2: "))
sum = num1 + num2
print("Sum is:", sum)
</details>
รับความยาวด้านจากผู้ใช้ แล้วแสดงพื้นที่
สูตร: พื้นที่ = ด้าน × ด้าน
<details> <summary>เฉลย</summary>
side = float(input("Enter the length of the side: "))
area = side * side
print("Area is:", area)
</details>
รับอุณหภูมิ (องศาเซลเซียส) แล้วแปลงเป็นฟาเรนไฮต์
สูตร: F = C × 9/5 + 32
<details> <summary>เฉลย</summary>
python
CopyEdit
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = celsius * 9/5 + 32
print("Temperature in Fahrenheit:", fahrenheit)
</details>
อย่าลืมแปลงค่าที่รับมาจาก input() ให้เป็น int หรือ float หากจะนำไปคำนวณ
input() รับค่าทุกอย่างเป็น "ข้อความ" (str) โดยค่าเริ่มต้น