User interaction and conditional 1-8

A user interaction:

···· input () function of the input

···· output () function output

# A = ( "Please enter your name") print ( "This man's name is" + a) = the person's name is XXX

# A = ( "any number") b = ( "another arbitrary number") If the input 1 and 2

print (a + b) = 12 because the data type is string received

c = int (a) d = int (b) print (c + d) = 3 calculates the data type needs to be first converted into an integer data type int then calculated.

 

Second flow control if statement: if elif else 

 if condition is determined:

   Implementation condition is true, executing the current code block.

 elif

   The condition is false, continue to judge below.

 else:

   Condition is false, the above code block is not executed, executing the current code block.

'''

money = 1000

if money > 5000:

   print ( "car")

 elif money > 3000:

   print ( "buy bicycle")

 elif money > 1000:

   print ( "shoes")

 else:

   print ( "do not buy")

 

Three nesting Note: Indent (Tab)

'''

P = input ( "You are men and woman?")

if P == "female" # == judgment, can only be a woman

  age = input ( "How old?")

  if int (age)> 30: #age age, type integer

    print ( "off")

  else:

    print ( "Come")

else:

  print ( "Go away")

'' '# Note indent

# In development, so as not more than three levels of nesting. if and else can be nested.

 

Guess you like

Origin www.cnblogs.com/alu-/p/11348159.html