In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
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
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.