ex26

修正后

 1 print("How old are you?", end=' ')
 2 age = input()
 3 print("How tall are you?", end=' ')
 4 height = input()
 5 print("How much do you weigh?", end=' ')
 6 weight = input()
 7 
 8 print(f"So, you're {age} old, {height} tall and {weight} heavy.")
 9 
10 from sys import argv
11 script, filename = argv
12 
13 txt = open(filename)
14 
15 print("Here's your file {filename}:")
16 print(txt.read())
17 
18 print("Type the filename again:")
19 file_again = input("> ")
20 
21 txt_again = open(file_again)
22 
23 print(txt_again.read())
24 
25 
26 print('Let\'s practice everything.')
27 print('You\'d need to know \'bout escapes') 
28 print('with \\ that do \n newlines and \t tabs.')
29 
30 poem = """
31 \tThe lovely world
32 with logic so firmly planted
33 cannot discern \n the needs of love
34 nor comprehend passion from intuition
35 and requires an explanation
36 \n\t\twhere there is none.
37 """
38 
39 print("--------------")
40 print(poem)
41 print("--------------")
42 
43 
44 five = 10 - 2 + 3 - 6
45 print(f"This should be five: {five}")
46 
47 def secret_formula(started):
48     jelly_beans = started * 500
49     jars = jelly_beans / 1000
50     crates = jars / 100
51     return jelly_beans, jars, crates
52 
53 
54 start_point = 10000
55 beans, jars, crates = secret_formula(start_point)
56 
57 # remember that this is another way to format a string
58 print("With a starting point of: {}".format(start_point))
59 # it's just like with an f"" string
60 print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.")
61 
62 start_point = start_point / 10
63 
64 print("We can also do that this way:")
65 formula = secret_formula(start_point)
66 # this is an easy way to apply a list to a format string
67 print("We'd have {} beans, {} jars, and {} crates.".format(*formula))
68 
69 
70 
71 people = 20
72 cats = 30
73 dogs = 15
74 
75 
76 if people < cats:
77     print ("Too many cats! The world is doomed!")
78 
79 if people < cats:
80     print("Not many cats! The world is saved!")
81 
82 if people < dogs:
83     print("The world is drooled on!")
84 
85 if people > dogs:
86     print("The world is dry!")
87 
88 
89 dogs += 5
90 
91 if people >= dogs:
92     print("People are greater than or equal to dogs.")
93 
94 if people <= dogs:
95     print("People are less than or equal to dogs.")
96 
97 
98 if people == dogs:
99     print("People are dogs.")

猜你喜欢

转载自www.cnblogs.com/shadowyuriya/p/10166592.html
ex2
今日推荐