发布时间:2019-09-22 07:40:18编辑:auto阅读(1598)
输出1到100之间的所有奇数和偶数:
num = 1 while num <=100: if num%2 == 0: print(num) num += 1 cai num = 1 while num <=100: if num%2 == 1: print(num) num += 1
猜年龄游戏的两种方法:
age = 50 flag = True while flag: user_input_age = int(input("Age is:")) if user_input_age == age: print("Yes") flag = False elif user_input_age > age: print("is bigger") else: print("is smaller") print("End") age = 50 while True: user_input_age = int(input("Age is:")) if user_input_age == age: print("Yes") break elif user_input_age > age: print("is bigger") else: print("is smaller") print("End")
break语句和continue语句。
print中的end语句:
#print("hello world.",end="__") # \n \r\n \r #print("hello world.",end="__") #print("hello world.",end="__") num1 = 0 while num1<=5: print(num1,end="_") num2 = 0 while num2<=7: print(num2,end="-") num2+=1 num1+=1 print() # print(end="\n") #0_0-1-2-3-4-5-6-7- #1_0-1-2-3-4-5-6-7-
输出#号,指定长高的长方形:
height = int(input("height:")) width = int(input("width:")) num_height = 1 while num_height <= height: num_width = 1 while num_width <= width: print("#",end="") num_width += 1 print() num_height += 1
上一篇: python之协程
下一篇: Python [6] IT资产管理(下)
47837
46379
37263
34722
29306
25964
24887
19943
19534
18014
5785°
6406°
5921°
5957°
7060°
5904°
5936°
6432°
6400°
7772°