笨办法学python 习题14 优化过 遇到问题的请看

print "\t what‘s you name?"
user_name = raw_input(‘>‘)

from sys import argv
script, = argv

prompt = ‘>‘

print "\t hi %s,I‘m the %s script"%(user_name,script)
print "\t I‘d like to ask you a few questions"

print "\t Do you like me %s"%(user_name)
likes = raw_input(prompt)

print "\twhere do you live %s?"%(user_name)
lives = raw_input(prompt)

print "\twhat kind of computer do you have?"
computer = raw_input(prompt)

print ‘‘‘
\t Alright,you say ‘%r‘ about liking me.
\t you live in ‘%r‘.Not sure where that is.
\t And you have a ‘%r‘ computer. Nice!
‘‘‘ %(likes,lives,computer)

原文地址:https://www.cnblogs.com/HL77961/p/9864553.html

时间: 2024-08-03 09:49:24

笨办法学python 习题14 优化过 遇到问题的请看的相关文章

笨办法学Python - 习题3: Numbers and Math

Exercise2是注释和井号 Comments and Pound Characters 具体详情请参考习题一,这里就不在做过多的赘述. 习题 3: 数字和数学计算 学习目标:了解Python中常用的算术运算符,并了解运算符之间的先后运算顺序 在各大常用的计算机语言中都有常见的算术运算符,Python也是大同小异,下面我们来了解一下Python中常见的算术运算符: 算术运算符 以下假设变量x = 10 ,y = 20 运算符 描述 实例 + 加 - 两个对象相加 x+y = 30 - 减 -

笨办法学Python - 习题8-10: Printing & Printing, Printing

目录 1.习题 8: 打印,打印 2.习题 9: 打印,打印,打印 3.习题 10: 那是什么? 3.1.转义序列: 4.习题总结: 1.习题 8: 打印,打印 学习目标:继续学习 %r 的格式化输出. 习题八中的练习代码是: #! -*-coding=utf-8 -*- formatter = "%r %r %r %r %r " print formatter % (1, "hello", [1,2,3], (1,2,3), {"name":&

笨办法学python 习题42 加分练习

3.创建一个新版本,里边使用两个 class,其中一个是 Map ,另一个是 Engine .提示: 把 play 放到 Engine 里面.. #coding=utf-8from sys import exitfrom random import randint class Map(object):    def __init__(self):               self.quips = ["You died. You kinda suck at this.","

笨办法学Python 练习13和14

原题: 1 from sys import argv 2 3 script, first, second, third = argv 4 5 print "The script is called:", script 6 print "Your first variable is:", first 7 print "Your second variable is:", second 8 print "Your third variabl

笨办法学 Python (Learn Python The Hard Way)

最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注释和井号 习题 3: 数字和数学计算 习题 4: 变量(variable)和命名 习题 5: 更多的变量和打印 习题 6: 字符串(string)和文本 习题 7: 更多打印 习题 8: 打印,打印 习题 9: 打印,打印,打印 习题 10: 那是什么? 习题 11: 提问 习题 12: 提示别人

笨办法学Python(十四)

习题 14:提示和传递 让我们使用 argv 和 raw_input 一起来向用户提一些特别的问题.下一节习题你会学习如何读写文件,这节练习是下节的基础.在这道习题里我们将用略微不同的方法使用 raw_input,让它打出一个简单的 > 作为提示符.这和一些游戏中的方式类似,例如 Zork 或者 Adventure 这两款游戏. 1 from sys import argv 2 3 script, user_name = argv 4 prompt = '> ' 5 6 print "

习题 5: 更多的变量和打印 | 笨办法学 Python

一. 简述 “格式化字符串(format string)” -  每一次你使用 ' ’ 或 " " 把一些文本引用起来,你就建立了一个字符串. 字符串是程序将信息展示给人的方式. 二. 代码 1 #!usr/bin/env python 2 # -*- coding:utf-8 -*- 3 4 # Author: xixihuang 5 # Date : 2016/08/31 09:52 AM 6 # Desc : 习题5:更多的变量与打印 7 # 键入更多的变量并且将它们打印出来.这

《笨办法学python第三版》习题26,原错误代码及正确代码

#import ex25 1 def break_words(stuff): 2 """This function will break up words for us.""" 3 words = stuff.split(' ') 4 return words 5 6 def sort_words(words): 7 """Sorts the words.""" 8 return sor

笨办法学Python(二十九)

习题 29: 如果(if) 下面是你要写的作业,这段向你介绍了"if语句".把这段输入进去,让它能正确执行.然后我们看看你是否有所收获. 1 people = 20 2 cats = 30 3 dogs = 15 4 5 6 if people < cats: 7 print "Too many cats! The world is doomed!" 8 9 if people > cats: 10 print "Not many cats!