零基础学习PythonTask2打卡


一 . 添加注释

print("I will now count my chickens:")#will get the quantity
print("Hens", 25 + 30 / 6) #get the numbers Hens
print("Roosters", 100 - 25 * 3 % 4) #get the numbers roosters
print("Now I will count the eggs:")#will get the eggs quantity
print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)#get the numbers
print("Is it true that 3 + 2 < 5 - 7?")#get the magnitude of these two things
print(3 + 2 < 5 - 7)#return True or False
print("What is 3 + 2?", 3 + 2)#ji suan jie guo
print("What is 5 - 7?", 5 - 7)#fan huijie guo
print("Oh, that's why it's False.")
print("How about some more.")#get the long sentence
print("Is it greater?", 5 > -2)#return True or False
print("Is it greater or equal?", 5 >= -2)
print("Is it less or equal?", 5 <= -2) 

运行结果:

I will now count my chickens:
Hens 30.0
Roosters 97
Now I will count the eggs:
6.75
Is it true that 3 + 2 < 5 - 7?
False
What is 3 + 2? 5
What is 5 - 7? -2
Oh, that's why it's False.
How about some more.
Is it greater? True
Is it greater or equal? True
Is it less or equal? False

二. 自己想要计算的东西.py

print("I will now count my candy:")#will get the quantity
print("chocolate",  100 / 50) #get the numbers chocolate
print("marshmallow", 25 * 3 % 4) #get the numbers marshmallow
print("Now I will count the tangerine:")#will get the tangerine quantity
print(3 + 2 + 1 - 5 + 1 - 4 + 6)#get the numbers
print("Is it true that 3 - 2 < 5 + 7?")#get the magnitude of these two things
print(3 - 2 < 5 + 7)#return True or False
print("What is 3 + 2?", 3 + 2)#ji suan jie guo
print("What is 5 - 7?", 5 - 7)#fan huijie guo
print("Oh, that's why it's False.")
print("How about some more.")#get the long sentence
print("Is it greater?", 5 > -2)#return True or False
print("Is it greater or equal?", 5 >= -2)
print("Is it less or equal?", 5 <= -2) 

运行结果:

I will now count my candy:
chocolate 2.0
marshmallow 3
Now I will count the tangerine:
4
Is it true that 3 - 2 < 5 + 7?
True
What is 3 + 2? 5
What is 5 - 7? -2
Oh, that's why it's False.
How about some more.
Is it greater? True
Is it greater or equal? True
Is it less or equal? False

 三. 改成自己的信息

my_name = 'xiaoyuer'
my_age = 18 # not a lie
my_height = 90 # inches
my_weight = 165 # lbs
my_eyes = 'Black'
my_teeth = 'White'
my_hair = 'black'
print(f"Let's talk about {my_name}.")
print(f"He's {my_height} inches tall.")
print(f"He's {my_weight} pounds heavy.")
print("Actually that's not too heavy.")
print(f"He's got {my_eyes} eyes and {my_hair} hair.")
print(f"His teeth are usually {my_teeth} depending on the coffee.")
# this line is tricky, try to get it exactly right
total = my_age + my_height + my_weight
print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}.")

运行结果:

Let's talk about xiaoyuer.
He's 90 inches tall.
He's 165 pounds heavy.
Actually that's not too heavy.
He's got Black eyes and black hair.
His teeth are usually White depending on the coffee.
If I add 18, 90, and 165 I get 273.

四. 找出有几处是字符串套字符串的 

types_of_people = 10
x = f"There are {types_of_people} types of people."
binary = "binary"
do_not = "don't"
y = f"Those who know {binary} and those who {do_not}."
print(x)
print(y)
print(f"I said: {x}")
print(f"I also said: '{y}'")
hilarious = False
joke_evaluation = "Isn't that joke so funny?! {}"
print(joke_evaluation.format(hilarious))
w = "This is 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.
I also said: 'Those who know binary and those who don't.'
Isn't that joke so funny?! False
This is the left side of...a string with a right side.

肉眼可见有5处呀(小编撒谎说有4处哈哈哈)

五. 列表相关操作

可以存储不同类型的数据

向列表中添加元素用 append(向尾部调添加)

                                 insert(向指定位置添加)

                                 extend(向尾部增加另一个列表的全部元素)

删除元素可以用 remove(删除列表中的指定元素,有多个的话,删除第一个)

                          pop(默认删除尾部的元素,也可以通过指定索引号删除指定元素)

                          clear(清空列表)

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值