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