博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Learn Python The Hard Way(12)
阅读量:6149 次
发布时间:2019-06-21

本文共 1299 字,大约阅读时间需要 4 分钟。

hot3.png

When you typed raw_input() you were typing the ( and ) characters which are parenthesis. 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 they know 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 their answer. This means we can completely rewrite our previous exercise using just raw_input to do all the prompting.

#!/usr/bin/env python# -*- coding: utf-8 -*-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)

result:

                          140106_BB8J_189901.jpg

Extra Credit

1. In Terminal where you normally run python to run your scripts, type: pydoc raw_input. Read what it says.

2. Get out of pydoc by typing q to quit.

3. Go look online for what the pydoc command does.

4. Use pydoc to also read about open, file, os, and sys . It's alright if you do  not understand those, just read           through and take notes about interesting things.

转载于:https://my.oschina.net/xtfjt1988/blog/401809

你可能感兴趣的文章
showdialog弹出窗口刷新问题
查看>>
java
查看>>
Vue.js连接后台数据jsp页面  ̄▽ ̄
查看>>
关于程序的单元测试
查看>>
mysql内存优化
查看>>
都市求生日记第一篇
查看>>
Java集合---HashMap源码剖析
查看>>
SQL优化技巧
查看>>
thead 固定,tbody 超出滚动(附带改变滚动条样式)
查看>>
Dijkstra算法
查看>>
css 动画 和 响应式布局和兼容性
查看>>
csrf 跨站请求伪造相关以及django的中间件
查看>>
MySQL数据类型--与MySQL零距离接触2-11MySQL自动编号
查看>>
生日小助手源码运行的步骤
查看>>
Configuration python CGI in XAMPP in win-7
查看>>
bzoj 5006(洛谷 4547) [THUWC2017]Bipartite 随机二分图——期望DP
查看>>
CF 888E Maximum Subsequence——折半搜索
查看>>
欧几里德算法(辗转相除法)
查看>>
面试题1-----SVM和LR的异同
查看>>
MFC控件的SubclassDlgItem
查看>>