Python基础之控制语句
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python基础之控制语句相关的知识,希望对你有一定的参考价值。
在Python 中有三种控制流语句——if、for 和while。 1.if语句Number = 23 Guess = int(input(‘Enter an integer : ‘)) if Guess == Number: print(‘Congratulations, you guessed it.‘) print(‘(but you do not win any prizes!)‘) elif Guess < Number: print(‘No, it is a little higher than that‘) else: print(‘No, it is a little lower than that‘) print(‘Done‘)
number = 23 Running = True while Running: Guess = int(input("Enter an integer:")) if Guess == Number: print("Congratulations, you guessed it.") elif Guess < Number: print("No, it is a little higher.") else: print("No, it is a little lower.") else: print("the while loop is over.") print("Done")
Enter an integer : 50 No, it is a little lower. Enter an integer : 22 No, it is a little higher. Enter an integer : 23 Congratulations, you guessed it. The while loop is over. Done
for i in range(1,5): print(i) else: print("The for loop is over")
以上是关于Python基础之控制语句的主要内容,如果未能解决你的问题,请参考以下文章