2015年1月25日 星期日

Exercise 12: Prompting People

Exercise 12: Prompting People

When you typed raw_input() you were typing the ( and ) characters, which are parenthesis characters. This is similar to when you used them to do a format with extra variables, as in "%s %s" % (x, y). For raw_input you can also put in a prompt to show to a person so he knows what to type. Put a string that you want for the prompt inside the () so that it looks like this:
y = raw_input("Name? ")
This prompts the user with "Name?" and puts the result into the variable y. This is how you ask someone a question and get the answer.
This means we can completely rewrite our previous exercise using just raw_input to do all the prompting.
1
2
3
4
5
6
age = raw_input("How old are you? ")
height = raw_input("How tall are you? ")
weight = raw_input("How much do you weigh? ")

print "So, you're %r old, %r tall and %r heavy." % (
    age, height, weight)

What You Should See

$ python ex12.py
How old are you?  38
How tall are you?  6'2"
How much do you weigh?  180lbs
So, you're '38' old, '6\'2"' tall and '180lbs' heavy.
=====================================================================
age = input("How old are you? ")
height = input("How tall are you? ")
weight = input("How much do you weigh? ")

print ("So, you're %r old, %r tall and %r heavy." % (
    age, height, weight))
>>> ==================== RESTART =======================
>>> 
How old are you? 18
How tall are you? 176
How much do you weigh? 76
So, you're '18' old, '176' tall and '76' heavy.
>>> 

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) 3) 使用database需先create建立資料庫 Node-Red 程式 [...