In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.