#!/user/bin/env python# -*- coding:utf-8 -*- # input() 可以让程序暂停工作# int(input('please input something:'))# % 取余运算 # [标识符]# prompt = "\n Tell me something,and i will repeat it back to you:"# message = ""## active = True# while active:# me…
7.1 函数input()的工作原理 函数input() 让程序暂停运行,等待用户输入一些文本.获取用户输入后,Python将其存储在一个变量中,以方便你使用. message = input("Tell me something, and I will repeat it back to you: ") print(message) Tell me something, and I will repeat it back to you: hello world hello world…
#1.编写一个程序,询问用户要租赁什么样的汽车,并打印. car = input("What's kind of cars dou you want to rent?,sir:") print('Let me see if I can find you a '+ car) print('\n') #2.编写一个程序,询问用户有多少人用餐.如果超过8人,就打印一条消息,指出没有空桌:否则指出有空桌 table = input("尊敬的先生/女士,请问订餐人数是多少?:"…
#!/user/bin/env python# -*- coding:utf-8 -*- # 1.从文件中读取数据with open('pi_digits.txt') as file_object: contents = file_object.read() # print(contents)# 末尾会多一行空行,read()到文件末尾时会返回一个空字符,rstrip()删除末尾空白 print(contents.rstrip()) # [有点问题] # 文件打开可以使用绝对路径和文件名 # 可…
7.1 创建多行字符串的方式: 01 prompt="if you tell me who you are, we can personalize the message you see." 02 prompt+="what is your first name? "; 03 04 name=input(prompt); 05 print("\nhello,"+name+'!'); >>> if you tell me who…
python变量赋值: python的变量赋值 可以是单引号 也可以是双引号python 变量赋值的时候不能加()的 比如 name = "My Name is GF"变量赋值的时候赋值会报错赋值字符串错误 解决错误可检查解释器解释报错的行号来判断打印变量:打印变量 需要紧挨着()比如 print(Name) 感悟:这是最基础的字符串操作,也就是小孩子的牙牙学语阶段,其实特别简单下一篇就是对字符串进行改动,比如大小写,移动等等.也是人性化的操作.比较基础代码应用即将应用开始.我要在每一…
#.餐馆:创建一个名为Restaurant的类,其方法_init_()设置两个属性:restaurant_name和cuisine_type. #创建一个名为describe_restaurant的方法和一个名为open_restaurant()的方法, #其中前者打印前述两项信息,而后者打印一条消息,指出餐馆正在营业 #根据这个类创建一个实例restaurant,分别打印其两个属性,再调用前述两个方法 class Restaurant(): #餐馆的基本信息 def __init__(self…
#!/user/bin/env python# -*- coding:utf-8 -*- # 用python中unittes中工具来测试代码 # 1.测试函数import unittestfrom name_function import get_formatted_name class NamesTestCase(unittest.TestCase): # 必须继承unittest.TestCase这个类 # 测试name_function.py def test_first_last_nam…
#!/user/bin/env python# -*- coding:utf-8 -*- # 类名采用的是驼峰命名法,即将类名中每个单词的首字母大写,而不使用下划线.# 对于每个类,都应紧跟在类定义后面包含一个文档字符串:简要描述类的功能,并遵循写函数的文档字符串时的格式约定# 每个模块也应当包含一个文档字符串,对其中的类可用于做什么进行描述.class Dog(): def __init__(self,name,age): '''__init__ 方法''' '''形参self必不可少,还必须…
#!/user/bin/env python# -*- coding:utf-8 -*- # 给形参指定默认值时,等号两边不要有空格 def function_name("parameter_0",parameter_1='default value')# 函数形参的位置很重要 传递参数使用关键字实参(一一对应的传递,可以不用理会顺序)# 默认值传递时候要指定传递(可以对应位置传递)# 返回值return 默认函数已经结束了 def get_formatted_name(frist_n…