python学习03——设计,与input有关
笨办法学python第36节,我写的代码如下:
from sys import exit def rule():
print "Congratulations! You made the right choice."
print "But is also a terrible choice."
print "You have to abide by the contract of the devil."
print "Input your choice: \n 1.dog \n 2.cat \n 3. panda" next = raw_input("> ") if next.isdigit():
next1 = int(next)
if next1 == 1:
print "Don't quarrel with me!"
elif next1 == 2:
print "Remember, good boyfriend won't quarrel with his girlfriend!"
elif next1 == 3:
print "Remember, don't quarrel with me!!!!!!!"
else:
print "Input a number in range(1,4)!" else:
print "please input a number"
exit(0) def start():
print "Do you want to be my boyfriend?"
print "input 'yes' or 'no' " next = raw_input("> ") if next == "yes":
rule()
elif next == "no":
print "How dare you!"
else:
print "You don't even know the rule, bye bye" start()
这个用的是raw_input("> "),下面的代码用的是input("> ")
from sys import exit def rule():
print "Congratulations! You made the right choice."
print "But is also a terrible choice."
print "You have to abide by the contract of the devil."
print "Input your choice: \n 1.dog \n 2.cat \n 3. panda" next = input("> ") if next in range(1,4): if next == 1:
print "Don't quarrel with me!"
elif next == 2:
print "Remember, good boyfriend won't quarrel with his girlfriend!"
else:
print "Remember, don't quarrel with me!!!!!!!" else:
print "please input a number in range(1,4)"
exit(0) def start():
print "Do you want to be my boyfriend?"
print "input 'yes' or 'no' " next = raw_input("> ") if next == "yes":
rule()
elif next == "no":
print "How dare you!"
else:
print "You don't even know the rule, bye bye" start()
注:
1. 第一个代码里面:next = raw_input("> "), 意思就是无论输入什么,都是字符串的类型,所以要在下面加上一句 next1 = int(next) 转换成数字进行判断。
2.第二个代码里面:用的 next = input("> "), 所以就不用 next.isdigit(): ,因为这个是对字符串进行的判断(参见上一节),这里的话就直接可以用 next in range(1,4):,但是应该注意的是在运行脚本的时候,如果输入字符串,要用“”引号引起来,否则会出现SyntaxError 。
3. 这两个函数均能接收字符串 ,但 raw_input() 直接读取控制台的输入(任何类型的输入它都可以接收)。而对于 input() ,它希望能够读取一个合法的 python 表达式,即你输入字符串的时候必须使用引号将它括起来,否则它会引发一个 SyntaxError 。
python学习03——设计,与input有关的更多相关文章
- python学习03-数据类型
一.基本数据类型--数字 布尔型 bool型只有两个值:True和False 之所以将bool值归类为数字,是因为我们也习惯用1表示True,0表示False. 以下是布尔值是False的各种情况: ...
- Python学习--03变量类型
变量赋值 Python中的变量不需要声明,变量的赋值操作既是变量声明和定义的过程. 每个变量在内存中创建,都包括变量的标识,名称和数据这些信息. 每个变量在使用前都必须赋值,变量赋值以后该变量才会被创 ...
- python学习03
字符串的基本使用 1.字符编码集 ASCII编码:外国人常用的大小写英文字母.数字和一些符号,一共127个字符,用1个字节(byte)可以涵盖完,也就是8个位,它将序列中的每个字节理解为一个字符. U ...
- python学习 03 函数 (只会执行一次return就不会往下执行)
1.调用函数只会执行一次return,而且执行return后不会往下执行
- python学习03字符串基本操作
'''字符串可以用单引号,双引号,三引号表示 '''#1.读取str1='I am a student!'#每一个字符对应一个下标,可以利用下标的方式来读取字符串对应的值——索引print(str1[ ...
- Python学习路程day16
Python之路,Day14 - It's time for Django 本节内容 Django流程介绍 Django url Django view Django models Django te ...
- Python学习(二)Python 简介
Python 简介 官方指南及文档 Python2.7官方指南(中文版):http://pan.baidu.com/s/1dDm18xr Python3.4官方指南(中文版):http://pan.b ...
- Python学习记录day6
title: Python学习记录day6 tags: python author: Chinge Yang date: 2016-12-03 --- Python学习记录day6 @(学习)[pyt ...
- Python学习记录day5
title: Python学习记录day5 tags: python author: Chinge Yang date: 2016-11-26 --- 1.多层装饰器 多层装饰器的原理是,装饰器装饰函 ...
随机推荐
- CSS下拉列表错误纠正
上一篇关于CSS制作下来列表的错误纠正. 在上一篇中,用CSS只做了下拉列表,但是鼠标不放在导航栏上的时候,下拉列表也是出来的.具体错误就是 div ul{ list-style:none; max- ...
- hihoCoder 1426 : What a Ridiculous Election(总统夶选)
hihoCoder #1426 : What a Ridiculous Election(总统夶选) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - ...
- Redis学习-基础环境介绍(二)
1.通过VMware安装了Centos6.8系统 2.Reids安装过程,需要GCC环境 »通过下面命令,根据提示直接安装 1 yum install gcc 3.Redis选用的是3.2.4(建议使 ...
- 学习UFT11.5历程(一)
博主三年来测试都是功能测试 看了虫师的文章,感觉是要学点东西.所以,听从虫师的话,不被眼花瞭乱的测试技术打扰,先学习UFT,再学习python. 再不学习感觉要被淘汰了...... 也不想有谈工资的时 ...
- python成长之路【第十二篇】:RabbitMQ入门
一.RabbitMQ介绍 解释RabbitMQ,就不得不提到AMQP(Advanced Message Queuing Protocol)协议. AMQP协议是一种基于网络的消息传输协议,它能够在应用 ...
- JS 之JSON
JSON是Javascript中的对象,其简单理解为下:
- TCP/IP 三次握手-四次挥手
TCP的建立需要三次握手,断开需要四次挥手. 首先三次握手: 首先,客户机向服务器发送请求报文,服务器回复ACK,并分配资源,而客户端接受到ACK后回复确认报文,并分配资源,此时三次握手完成. 四次挥 ...
- SQL Tuning / SQL 性能 优化 调优
Some key concents regarding SQL optimization predicate selectivity (column unique ratio) / cardinali ...
- debug 断点无效
如果出现这样的情况 需要在debug下配置 配置好之后,断点测试即可,亲测有效.
- Linq常用语法详细
1.简单的linq语法 //1 var ss = from r in db.Am_recProScheme select r; //2 var ss1 = db.Am_recProScheme; // ...