Exercise 14: Prompting And Passing

from sys import argv
script, user_name = argv
prompt = ‘> ‘
print "Hi %s, I‘m the %s script." % (user_name, script)
print "I‘d like to ask you a few questions." print "Do you like me %s?" % user_name
likes = raw_input(prompt)
print "Where do you live %s?" % user_name
lives = raw_input(prompt)
print "What kind of computer do you have?"
computer = raw_input(prompt)
print """
Alright, so you said %r about liking me.
You live in %r. Not sure where that is.
And you have a %r computer. Nice.
""" % (likes, lives, computer)

Notice though that we make a variable prompt that is set to the prompt we want, and we give that to raw_input
instead of typing it over and over. Now if we want to make the prompt something else, we just change it in this one spot
and rerun the script.

时间: 2024-11-08 00:26:08

Exercise 14: Prompting And Passing的相关文章

C - The C Answer (2nd Edition) - Exercise 1-4

/* Write a program to print the corresponding Celsius to Fahrenheit table. */ #include <stdio.h> /* print Celsius-Fahrenheit table for celsius = 0, 20, ..., 300; floating-point version */ main() { float fahr, celsius; int lower, upper, step; lower =

Exercise 12: Prompting People

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)

Python Index

Table Of ContentsThe Hard Way Is EasierExercise 0: The SetupExercise 1: A Good First ProgramExercise 2: Comments And Pound CharactersExercise 3: Numbers And MathExercise 4: Variables And NamesExercise 5: More Variables And PrintingExercise 6: Strings

The C Programming Language——Exercise solutions of the chapter one (1st)

Recently,I have been reading the book The C Progrmming Lanuage(2nd Edition),which written by Dennis M.Ritchie and Brian W.Kernighan.The are many useful and elegant exercises in the book.Here is my solutions to the exercises of the first chapter but n

MIT 6.828 学习笔记6 Lab4实验报告

Lab4实验报告 开始之前,为了弄懂 mpconfig 与 lapic,可能需要阅读 Intel processor manual 和 MP Specification,相关资源可以在课程中找到 Execrise 1 Implement mmio_map_region in kern/pmap.c. // mmio_map_region() uintptr_t ret = base; size = ROUNDUP(size, PGSIZE); base = base + size; if (ba

apue.h头文件(UNIX环境高级编程)

apue.h是作者自己写的一个文件,包含了常用的头文件,系统不自带.其中包含了常用的头文件,以及出错处理函数的定义.使用起来确实很方便. apue.h内容如下:   #ifndef _APUE_H #define _APUE_H #define _XOPEN_SOURCE   600  /* Single UNIX Specification, Version 3 */ #include <sys/types.h>       /* some systems still require thi

相亲数

程序地址:http://www.cheemoedu.com/exercise/14 问题描述: 220的真因数之和为1+2+4+5+10+11+20+22+44+55+110=284284的真因数之和为1+2+4+71+142=220毕达哥拉斯把这样的数对A.B称为相亲数:A的真因数之和为B,而B的真因数之和为A.求100000以内的相亲数. 我的代码: def perfect(n):     a=1     b=n     s=0     while a<b:         if n%a==

Exercise 1.14 count change的时间复杂度

题目: Draw the tree illustrating the process generated by the count-change procedure of section 1.2.2 in making change for 11 cents. What are the orders of growth of the space and number of steps used by this process as the amount to be changed increas

CSSE1001 Supplementary Programming Exercise

CSSE1001 Supplementary Programming ExerciseCreate a simple banking application with a graphical user interface (GUI) for a banking system.The GUI is to be written from the perspective that the user is an employee of the bank (e.g. a teller).A bank ha