首页 > IT职业 > IT图书 > python while循环
输出1到100之间的所有奇数和偶数:
num = 1 while num
|
猜年龄游戏的两种方法:
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 rn r#print("hello world.",end="__")#print("hello world.",end="__") num1 = 0 while num1
|
输出#号,指定长高的长方形:
height = int(input("height:"))width = int(input("width:")) num_height = 1 while num_height
|
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4692/viewspace-2810955/ ,如需转载,请注明出处,否则将追究法律责任。