Search
Při programování často potřebujeme vykonat určité operace opakovaně. K tomu se hodí tzv. funkce.
def
def jmenoFunkce( parametry ): telo_funkce
Maximum ze dvou čísel:
def maximum(x,y): if x>y: return x else: return y
return
max = maximum(2,0.5) print(max) # nebo rovnou muzeme predat jiné funkci a = 6 b = 7 print("Maximum z ",a," a ", b, " je ", maximum(a,b))
def hello(): print("Hello World!")
hello()
def maximum2(x,y): if (x > y): return x, True else: return y, False
maxValue, info = maximum2(5,6) #zkusime predat printu: print("Maximum z 5,6 je ", maximum2(5,6))
quit()
if (spatny_vstup): quit()
input()
print( argumenty )
int( argument )
float( argument )
str( argument )
soucet_delitelu
gcd1(a,b)
gcd2(a,b)
ord('A')
chr(65)
convert_num_to_month
convert_month_to_num
month=['leden','unor','brezen','duben','kveten','cerven','cervenec','srpen','zari','rijen','listopad','prosinec']
min(a,b)
max(a,b)
area(radius)
d2r(angle)
r2d(angle)
normalize(angle)
for
while
'x'
' '
'|'
'-'
Např. pro vstup 10 vypadá výsledek takto:
| | | | | | | | | ------------------- |x| |x| |x| |x| |x ------------------- | |x| | |x| | |x| ------------------- |x| |x| |x| |x| |x ------------------- | | | |x| | | | |x ------------------- |x|x|x| |x| |x|x|x ------------------- | | | | | |x| | | ------------------- |x| |x| |x| |x| |x ------------------- | |x| | |x| | |x| ------------------- |x| |x|x|x| |x| |x
twohundredfiftyseventhousandthreehundredseventyfive
ERROR
one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety, hundred, thousand
1000
onethousand
120
onehundredtwenty
Vstup: twohundredfiftyseventhousandthreehundredseventyfive Výstup: 257375
Vstup: 543210 Výstup: fivehundredfortythreethousandtwohundredten
Vstup: tentwenty Výstup: ERROR
Vstup: seventytwothreehundred Výstup: ERROR