ex11~ex12有关于raw_input

ex11开始接触人机互动模式,我也喜欢叫它黑盒模式,一端有input一端有output,这也是软件的基础模型,想想我们学习编程的目的是什么,就是想让我们写出的程序处理我们想要它得理的事情,并把结果返给我们看。

raw_input()就是让你input的接口,而且可以带提示的,例如我想写一段代码,但是要提醒你输入指定内容,raw_input("your name? "),但我测试后有一个地方要注意,就是所有通过这个raw_input()输入都是字符串格式(string)

在网上搜了一些关于格式的一些代码

  • 直接字符串的就不写了
  • 输入整数
    nAge = int(raw_input("input your age plz:\n"))  
    

if nAge > 0 and nAge < 120:
print 'thanks!'
else:
print 'bad age'
print 'your age is %d\n' % nAge
```

  • 输入浮点数型
fWeight = 0.0  
fWeight = float(raw_input("input your weight\n"))  
print 'your weight is %f' % fWeight 
 

暂且先写这两个例子,记住输入的是string 就行了,想要把数据处理,就要再转换

还有个知识点就是pydoc相当于帮助文档,在window下powershell中输入python python -m pydoc raw_input,就能查看raw_input相关内容的帮助文档

把这两课的代码贴上
ex11

#coding=utf-8
print "How old are you?",
age = raw_input()
print "How tall are you?",
height = raw_input()
print "How much do you weight?",
weight = raw_input()


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

ex12

#coding=utf-8

age = raw_input("How old are you? ")
height = raw_input("How tall are you? ")
weight = raw_input("How much do you weight?") 

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

比较一下两者的区别

你可能感兴趣的:(ex11~ex12有关于raw_input)