1、有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少? 2、企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数? 3、一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少? 4、输入某年某月某日,判断这一天是这一年的第几天? 5、输入三个整数x,y,z,请把这三个数由小到大输出。 6、斐波那契数列。 7、将一个列表的数据复制到另一个列表中。 8、输出 9*9 乘法口诀表。 9、暂停一秒输出。 10、暂停一秒输出,并格式化当前时间。
1、有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少? 方法一:
1 l = []2 for i in range(1,5):3 for j in range(1,5):4 for m in range(1,5):5 if len({i,j,m}) == 3:6 l.append(i * 100 + j * 10 + m)7 print(l)8 print(len(l))
1 [123, 124, 132, 134, 142, 143, 213, 214, 231, 234, 241, 243, 312, 314, 321, 324, 341, 342, 412, 413, 421, 423, 431, 432]2 24
方法二:
1 from itertools import permutations2 3 l = []4 for i in permutations([1, 2, 3, 4], 3):5 l.append(i)6 7 print(l)8 print(len(l))
1 [(1, 2, 3), (1, 2, 4), (1, 3, 2), (1, 3, 4), (1, 4, 2), (1, 4, 3), (2, 1, 3), (2, 1, 4), (2, 3, 1), (2, 3, 4), (2, 4, 1), (2, 4, 3), (3, 1, 2), (3, 1, 4), (3, 2, 1), (3, 2, 4), (3, 4, 1), (3, 4, 2), (4, 1, 2), (4, 1, 3), (4, 2, 1), (4, 2, 3), (4, 3, 1), (4, 3, 2)]2 24
2、企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数? 方法一:
1 # 这是最弱的方法,然而我想到的就是这种。。 2 a = [1000000,600000,400000,200000,100000,0] 3 b = [0.01,0.015,0.03,0.05,0.075,0.1] 4 x = int(input('销售利润是:')) 5 6 if x >= a[0]: 7 bonus = (x - a[0]) * b[0] + 400000 * b[1] + 200000 * b[2] + 200000 * b[3] + 100000 * b[4] + 100000 * b[5] 8 print('提成是:',bonus) 9 elif a[0] > x >= a[1]:10 bonus = (x - a[1]) * b[1] + 200000 * b[2] + 200000 * b[3] + 100000 * b[4] + 100000 * b[5]11 print('提成是:', bonus)12 elif a[1] > x >= a[2]:13 bonus = (x - a[2]) * b[2] + 200000 * b[3] + 100000 * b[4] + 100000 * b[5]14 print('提成是:', bonus)15 elif a[2] > x >= a[3]:16 bonus = (x - a[3]) * b[3] + 100000 * b[4] + 100000 * b[5]17 print('提成是:', bonus)18 elif a[3] > x >= a[4]:19 bonus = (x - a[4]) * b[4] + 100000 * b[5]20 print('提成是:', bonus)21 elif a[4] > x >= a[5]:22 bonus = (x - a[5]) * b[5]23 print('提成是:', bonus)24 elif x
1 销售利润是:2000012 提成是: 17500.05
方法二:
1 # 参考别人的 2 a = [1000000, 600000, 400000, 200000, 100000, 0] 3 b = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1] 4 count = 0 5 while count a[n]:10 tmp = (x-a[n])*b[n] # 计算该级别的提成11 sum += tmp12 x = a[n] # 后续的每一级都计算满额提成13 print(sum)14 count += 1
3. Nach Addition von 100 ist es eine vollständige Zahl Zahl Eine Quadratzahl plus 168 ist eine perfekte Quadratzahl. Was ist diese Zahl?
Methode 1:
import math x = -99 # 这个值是后面看别人答案时想到的,x+100必须大于0while x <pre class="brush:php;toolbar:false"># print(x) x += 1
Methode 2: Nachdem ich die Gedanken anderer Menschen gelesen habe, fühle ich mich geistig zurückgeblieben.
'''1、则:x + 100 = n2, x + 100 + 168 = m2 2、计算等式:m2 - n2 = (m + n)(m - n) = 168 3、设置: m + n = i,m - n = j,i * j =168,i 和 j 至少一个是偶数 4、可得: m = (i + j) / 2, n = (i - j) / 2,i 和 j 要么都是偶数,要么都是奇数。 5、从 3 和 4 推导可知道,i 与 j 均是大于等于 2 的偶数。 6、由于 i * j = 168, j>=2,则 1
4. Geben Sie einen bestimmten Monat und Tag eines bestimmten Jahres ein und bestimmen Sie, welcher Tag im Jahr dieser Tag ist?
Methode 1:
import datetime Y = int(input('年:')) m = int(input('月:')) d = int(input('日:')) days = datetime.datetime(Y,m,d) - datetime.datetime(Y,1,1) + datetime.timedelta(1) # 减去当年1月1日n = int(str(days).split(' ')[0])print(n) 年:2003月:12日:2 336
Methode 2:
import time# D=input("请输入年份,格式如XXXX-XX-XX:")D='2017-4-3'd=time.strptime( D,'%Y-%m-%d').tm_yday# print("the {} day of this year!" .format(d))print(d)print(time.strptime( D,'%Y-%m-%d'))# 或使用datetime模块import datetimeprint(datetime.date(2017,4,3).timetuple().tm_yday)print(datetime.date(2017,4,3).timetuple())
93time.struct_time(tm_year=2017, tm_mon=4, tm_mday=3, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=93, tm_isdst=-1)93time.struct_time(tm_year=2017, tm_mon=4, tm_mday=3, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=93, tm_isdst=-1)
5. Geben Sie diese drei Zahlen von klein nach groß ein.
Methode 1
L = [a,b,c] L.sort()print('\n'.join(l))
Methode 2:
1 # 最弱智的做法 2 # a = input('a=') 3 # b = input('b=') 4 # c = input('c=') 5 a = 10 6 b = 20 7 c = 30 8 9 l = []10 11 l.append(a)12 if b a:17 l.append(c)18 else:19 l.insert(1,c)20 else:21 l.append(b)22 if c b:25 l.append(c)26 else:27 l.insert(1,c)28 29 print('\n'.join(l))
Methode 3:
# 冒泡法a=[1,3,5,2,4,5,7] n=len(a)for i in range(0,n): for j in range(i,n) : if (a[i] >= a[j] ): a[i],a[j] = a[j],a[i]print(a)
[1, 2, 3, 4, 5, 5, 7]
6、斐波那契数列。 方法一:
l = [0,1]def f(n):for x in range(n): l.append(l[x]+l[x+1]) f(20)print(l)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946]
Methode 2:
# 使用递归def fib(n):if n == 1 or n == 2:return 1return fib(n - 1) + fib(n - 2)# 输出了第10个斐波那契数列print(fib(20))
7、将一个列表的数据复制到另一个列表中。
a = list(range(20)) b = a[:]print(a)print(b)print(id(a))print(id(b))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]2030007944584 2030007104200
8、输出 9*9 乘法口诀表。
1 # 先百度一下乘法口诀表长什么样子,怎么排列的 2 ''' 3 乘法口诀表如下: 4 1*1=1 5 2*1=2 2*2=4 6 3*1=3 3*2=6 3*3=9 7 4*1=4 4*2=8 4*3=12 4*4=16 8 5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 9 6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=3610 7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=4911 8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=6412 9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=8113 '''14 formula = '{a} * {b} = {c}'15 16 s = ''17 for i in range(1,10):18 print(s)19 s = ''20 for j in range(1,i+1):21 s += formula.format(a=i,b=j,c=i*j) + ' '22 # print(formula.format(a=i,b=j,c=i*j))
1 * 1 = 1 2 * 1 = 2 2 * 2 = 4 3 * 1 = 3 3 * 2 = 6 3 * 3 = 9 4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36 7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49 8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64
9、暂停一秒输出。
import timefor n in range(1,10):print(n) time.sleep(1)
10、暂停一秒输出,并格式化当前时间。
import timefor i in range(5): struct_time = time.localtime(time.time()) t = time.strftime('%Y-%m-%d %H:%M:%S',struct_time) t = time.strftime('%Y-%m-%d',struct_time)print(t) time.sleep(1)
Das obige ist der detaillierte Inhalt vonTeilen Sie ein Beispiel für eine Python-Übung. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Arraysinpython, besondersvianumpy, arecrucialInScientificComputingFortheirefficience undvertilität.1) Sie haben festgelegt, dass die Fornerikerne, Datenanalyse und Machinelarning.2) Numpy'SimplementationIncensuresFasteroperationsdanpythonlisten.3) Araysensableableableableableableableableableableableableableableableableableableableableableableableableableable

Sie können verschiedene Python -Versionen mithilfe von Pyenv, Venv und Anaconda verwalten. 1) Verwalten Sie PYENV, um mehrere Python -Versionen zu verwalten: Installieren Sie PyEnv, setzen Sie globale und lokale Versionen. 2) Verwenden Sie VenV, um eine virtuelle Umgebung zu erstellen, um Projektabhängigkeiten zu isolieren. 3) Verwenden Sie Anaconda, um Python -Versionen in Ihrem Datenwissenschaftsprojekt zu verwalten. 4) Halten Sie das System Python für Aufgaben auf Systemebene. Durch diese Tools und Strategien können Sie verschiedene Versionen von Python effektiv verwalten, um den reibungslosen Betrieb des Projekts zu gewährleisten.

NumpyarrayShaveseveraladVantagesOverStandardPythonArrays: 1) SiearemuchfasterDuetoc-basiert, 2) sie istaremoremory-effizient, insbesondere mit mit LaShlargedatasets und 3) sie können sich mit vektorisierten Funktionsformathematical und Statistical opertical opertical opertical operticaloperation, Making

Der Einfluss der Homogenität von Arrays auf die Leistung ist doppelt: 1) Homogenität ermöglicht es dem Compiler, den Speicherzugriff zu optimieren und die Leistung zu verbessern. 2) aber begrenzt die Typ -Vielfalt, was zu Ineffizienz führen kann. Kurz gesagt, die Auswahl der richtigen Datenstruktur ist entscheidend.

TocraftexecutablePythonScripts, folge theseBestPractices: 1) addashebangline (#!/Usr/bin/envpython3) tomakethescriptexcutable.2 SetPermissions withchmod xyour_script.py.3) organisation -bithacleardocstringanduseInname == "__ __": FormAcleardocstringanduseInname

NumpyarraysarebetterFornumericaloperations und multi-dimensionaldata, whilethearraymoduleiStableforbasic, an Gedächtniseffizienten

NumpyarraysarebetterforeheavynumericalComputing, während der projectwithsimpledatatypes.1) numpyarraysoferversatility und -PerformanceForlargedataSets und Compoxexoperations.2) thearraysoferversStility und Mächnory-Effefef

ctypesallowscreatingandmanipulationsc-stylearraysinpython.1) usectypestoInterfaceWithClibraryForperformance.2) createCec-stylearraysFornumericalComputationen.3) PassarrayStocfunctionsFectionFicecher-Operationen.


Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

Video Face Swap
Tauschen Sie Gesichter in jedem Video mühelos mit unserem völlig kostenlosen KI-Gesichtstausch-Tool aus!

Heißer Artikel

Heiße Werkzeuge

SAP NetWeaver Server-Adapter für Eclipse
Integrieren Sie Eclipse mit dem SAP NetWeaver-Anwendungsserver.

DVWA
Damn Vulnerable Web App (DVWA) ist eine PHP/MySQL-Webanwendung, die sehr anfällig ist. Seine Hauptziele bestehen darin, Sicherheitsexperten dabei zu helfen, ihre Fähigkeiten und Tools in einem rechtlichen Umfeld zu testen, Webentwicklern dabei zu helfen, den Prozess der Sicherung von Webanwendungen besser zu verstehen, und Lehrern/Schülern dabei zu helfen, in einer Unterrichtsumgebung Webanwendungen zu lehren/lernen Sicherheit. Das Ziel von DVWA besteht darin, einige der häufigsten Web-Schwachstellen über eine einfache und unkomplizierte Benutzeroberfläche mit unterschiedlichen Schwierigkeitsgraden zu üben. Bitte beachten Sie, dass diese Software

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Notepad++7.3.1
Einfach zu bedienender und kostenloser Code-Editor

VSCode Windows 64-Bit-Download
Ein kostenloser und leistungsstarker IDE-Editor von Microsoft
