第13节--条件语句和循环语句

1. if 语句

demo

if condition:
     do something
elif other_condition:
     do something
else:
     do something

code

# if statement example

number = 59
guess = int(input("Enter an integer: "))
# print("guess is: "+str(guess))

if guess == number:
    print("you are right")
elif guess < number:
    print("the number is higher than that")
else:
    print("the number is lower than that")
print("done")

2. for语句

code

# for loop example
for i in range(1,10):
    print(i)
else:
    print("for loop is over")


a_list = [1,3,5,7,9]
for i in a_list:
    print(i)

a_tuple = (2,4,6,8,10)
for i in a_tuple:
    print(i)

a_dict = {"xiao":1,"shu":2,"yi":3}

for ele in a_dict:
    print(ele)
    print(a_dict[ele])

for key,value in a_dict.items():
    print(key,value)

console

1
2
3
4
5
6
7
8
9
for loop is over
1
3
5
7
9
2
4
6
8
10
yi
3
shu
2
xiao
1
yi 3
shu 2
xiao 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值