Python学习笔记(九)

1.if 和 for

'''
Created on 2017年10月17日

@author: yanmengf
'''
# coding:utf-8
#if语句
from Tuple_List_Compare import a_tuple
number = 29
guess = int(input("Enter an integer :"))
if guess == number:
    print("Bingo! you guessed it right.")
    print("But you do not win any prizes!")
elif guess < number:
    print("No, the number is higher than that")
else:
    print("No, the number is lower than that")
print("Done")
#for循环语句
for i in range(1,10):
    print(i)
else:
    print("The for loop is over")

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

a_tuple = (1,3,5,7,9)
for i in a_tuple:
    print(i)
a_dict = {"Tom":111,"Jerry":222,"Cathy":333}
for i in a_dict:
    print(i)
    print(a_dict[i])

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

2.while循环

number = 29
i = 0
guess_flag = False

while guess_flag == False:
    guess = int(input("Enter an integer:"))
    if guess == number:
        i=i+1
        guess_flag=True
    elif guess < number:
        i=i+1
        print("No, the number is higher than that, keep guessing")
    else:
        i=i+1
        print("No, the number is lower than that, keep guessing")
print("you guessed:"+str(i)+" times")
print("Bingo! you guessed it right.")
print("(but you do not win any prizes)")
print("Done")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值