2015年1月25日 星期日

Exercise 11: Asking Questions

Exercise 11: Asking Questions

Now it is time to pick up the pace. You are doing a lot of printing to get you familiar with typing simple things, but those simple things are fairly boring. What we want to do now is get data into your programs. This is a little tricky because you have to learn to do two things that may not make sense right away but trust me and do it anyway. It will make sense in a few exercises.
Most of what software does is the following:
  1. Take some kind of input from a person.
  2. Change it.
  3. Print out something to show how it changed.
So far you have been printing strings, but you haven't been able to get any input from a person. You may not even know what "input" means, but type this code in anyway and make it exactly the same. In the next exercise we'll do more to explain input.

1
2
3
4
5
6
7
8
9
print "How old are you?",
age = raw_input()
print "How tall are you?",
height = raw_input()
print "How much do you weigh?",
weight = raw_input()

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

What You Should See

$ python ex11.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.

print ("How old are you?"),
age = input()
print ("How tall are you?"),
height = input()
print ("How much do you weigh?"),
weight = input()

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

>>> ================= RESTART ===================
>>> 
How old are you?
12
How tall are you?
176
How much do you weigh?
67
So, you're '12' old, '176' tall and '67' heavy.
>>> 

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...