Python-input函式

大芒果發表於2020-11-22

4.6 input函式

# input函式為python系統函式。
name = input("Please enter your name: ")
print("Hello, " + name.title() + "!")

age = input("How old are you? ")  # age is a string.
age = int(age)  # Now age is an integer.
if age >= 12 and age < 60:
    print('You can ride the roller coaster.')

# 讓使用者選擇何時退出:
prompt = "\nTell me something, and I will repeat it back to you:"
prompt += "\nEnter 'quit' to end the program. "
message = ""
while message != 'quit':
    message = input(prompt)
    print(message.upper())


輸出結果
在這裡插入圖片描述

相關文章