Python入门

python-习题6~10

徘徊边缘 提交于 2020-02-29 08:55:02
习题 6:字符串(string)和文本 x = "There are %d types of people."%10 binary = "binary" do_not= "don't" y = "Those who know %s and those who %s."%(binary,do_not) #定义变量,将要输出的内容存放到变量x,y, # binary,do_not. print x print y print "I said: %r."%x # ① print "I also said:'%s'."%y # ② hilarious = False joke_evaluation = "Isn't that joke so funny?!%r" # 定义变量 print joke_evaluation %hilarious # ③ ④ w = "This the left side of……" e = "a string with a right side." print w + e # ⑤ 运行结果: There are 10 types of people. Those who know binary and those who don't. I said: 'There are 10 types of people.'. # 变量x中的""变成了'' I also

Python-习题11~15

杀马特。学长 韩版系。学妹 提交于 2019-11-30 15:06:44
习题 11:提问 print "How old are you?", age = raw_input() print "How tall are you?", height = raw_input() print "How much do you weight?", weight = raw_input() print "So,you're %r old,%rtall and %r heavy." %( age,height,weight) 运行结果: How old are you? 35 How tall are you? 6'2'' how much do you weight? 180lb So,you're '35' old,"6'2''"tall and '180lb' heavy. 加分题: 1. raw_input 不管用户输入什么类型的都会转变成字符型 2. 另:input会根据用户输入变换相应的类型,而且如果要输入字符和字符串的时候必须要用引号包起来。 3. 自己再写一段类似格式的: print "How many times did you go to the park?", times = raw_input() print "How often do you go home a week?", fluence = raw_input() print