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.")

 

转载于:https://www.cnblogs.com/shadowyuriya/p/10166592.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值