What are the conditional statements in Python
Xiaobian to share with you what are the conditional statements in Python, I believe most people do not know how, so share this article for your reference, I hope you have a lot of gains after reading this article, let's go to understand it together!
if"" conditional statement: ifif... elseif... elif... elseif statement format: if condition: Condition holds Statement to be executed Condition: Operator composition---> bool""print(1)print(2)result = input ('please input (y/n):') if result == 'y': print('good~')print('-'*20)if…elseif... Form of statement: if condition: The condition holds for the statement to be executed else: Statements executed when the condition does not hold
Exercise:
#random number import randomram = random. randomint (1, 10)guess = input("Please enter your guess: ")if ram == int(guess): print ('guess right') else: print ('guess wrong') if…elif…elseif... elif... else format if Condition 1: Condition 1 holds the statement to be executed elif Condition 2: Statement executed when condition 2 holds elif condition 3: The statement executed when condition 3 holds else: Practice when conditions 1, 2 and 3 are not met: #Personnel Management System #Functions: Add employees, delete employees, query employees, modify employee information. print ('-'*20, ' Welcome to Personnel Management System','-'*20)choice = input ('Please select function: \n1.Add employees\n2.Delete employees\n3.Query employees\n4.Modify employee information\n')#Compare choices one by one if choice == '1': print ('Add employee') elif choice == '2': print ('delete employee') elif choice == '3': print ('query employee') elif choice == '4': print ('Modify employee information') else: print ('typo ') The above is "What are conditional statements in Python" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!