输出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 |
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦