26 python language to write and judge odd and even dynamic output diamond eva
Exercise to judge odd and even number # 1. Write Python program to judge whether the variable x is odd or even. # 2. To rewrite question 1, the variable x needs to be entered from the Python console. # question 1 # coding:utf-8x = 5a = x%2#print (a) if a = 0: print ("the value of x is even") else: print ("x is odd") print ("-")''while True: # this is to run a The while loop exits the loop x = input ("Please enter a number:") if x = "end": break num = int (x) if num% 2 = 0: print (x + "accidental") else: print (x + "is odd")''print ("-") when the end is executed. -") y = input (" Please enter a number: ") # this is a loop I wrote myself and nums = int (y) if nums% 2 = = 0: print (y +" is accidental ") else: print (y +" is odd ") # method 2 this is also possible x = input (" Please enter one Number: ") a = int (x) b = a%2if b = 0: print (" the value of x is even ") else: print (" x is odd ")-exercise explanation 2: dynamic output diamond # 3. Write Python program, use while loop to print a diamond, # diamond to be printed with an asterisk (*), the number of rows of the diamond needs to be entered from the console # the number of lines must be odd # * number * string 4 *'a'= aaaaline = input ('Please enter the number of lines (must be odd):') line = int (line) if line% 2! = 0: maxSpaceNum = line / / 2 # the maximum number of spaces per line I = 1 lineSpaceNum = maxSpaceNum # the number of spaces on the current line # output upper triangle while lineSpaceNum > = 0: # output the space print ("* lineSpaceNum") to the left of each line of asterisk End= "") # output the asterisk print ("*" * (2 * I-1)) lineSpaceNum-= 1 I + = 1 I-= 2 lineSpaceNum + = 2 # of each line to generate the lower triangle while lineSpaceNum