Download presentation
Presentation is loading. Please wait.
Published by歙堂 占 Modified over 7 years ago
1
Števila in izrazi Naslov teme:Spremenljivka, operator, izraz in funkcija ure: 9 in 10 Učna metoda: demonstracija, samostojno delo Učni pripomočki: Računalnik, projektor, priročnik, vaje Smotri: Dijak zna: Prirediti spremenljivko razume osnovne tipe podatkov Uporabi osnovne operatorje Pozna nize Uporabi knjižnice (math)
2
Števila in izrazi Izrazi: Primer programa: print "2 + 2 je ", 2+2
99 = 100 – 1 print "(33 + 2) / = ",(33 + 2) / (33 + 2) / = 18.5 Lahko si ogledaš film
3
Python ima 6 osnovnih opratorjev za števila
operacija znak primer potenciranje ** 5 ** 2 == 25 množenje * 2 * 3 == 6 deljenje (celoštevilčno) / 14 / 3 == 4 ostanek % 14 % 3 == 2 seštevanje + 1 + 2 == 3 odštevanje - 4 - 3 == 1 Vrstni red operatorjev: oklepaji, potence, množenje/deljenje, odštevanje, seštevanje
4
print "14 / 3 = ",14 / 3 14 / 3 = 4 print "14 % 3 = ",14 % #ostanek pri celoštevilčnem deljenju 14 % 3 = 2 print "14.0 / 3.0 =",14.0 / 3.0 14.0 / 3.0 = print "14.0 % 3.0 =",14 % 3.0 14.0 % 3.0 = 2.0 print "14.0 / 3 =",14.0 / 3 14.0 / 3 = print "14.0 % 3 =",14.0 % 3 14.0 % 3 = 2.0 print "14 / 3.0 =",14 / 3.0 14 / 3.0 = print "14 % 3.0 =",14 % 3.0 14 % 3.0 = 2.0
5
Ukaz print “Prvi razred" print "1+1 =",1+1 print "2+4 =",2+4 print "5-2 =",5-2 print print “Tretji class" print " =",243-23 print "12*4 =",12*4 print "12/3 =",12/3 print "13/3 =",13/3," R ",13%3 print "Junior High" print " =", print "(4+3)*2 =",(4+3)*2 print "4+3*2 =",4+3*2 print "3**2 =",3**2 Izpis Prvi razred 1+1 = 2 2+4 = 6 5-2 = 3 Tretji class = 220 12*4 = 48 12/3 = 4 13/3 = 4 R 1 Junior High = 61.44 (4+3)*2 = 14 4+3*2 = 10 3**2 = 9
6
Vhodni podatki in spremenljivke
print “Stop!" s = raw_input(“Kdo je? ") print “Lahko vstopiš,", s Ob zagonu se pojavi: Stop! Kdo je? Poldek #vneseš ime Lahko vstopiš, Poldek Oglej si film
7
Še nekaj primerov a = 123.4 b23 = 'Spam' ime = “Franci" b = 432
c = a + b print "a + b is", c a + b is 555.4 print “ime ti je", ime ime ti je Franci print "Sorted Parts, After Midnight or",b23 Sorted Parts, After Midnight or Spam num = input("Type in a Number: ") str = raw_input("Type in a String: ") print "num =", num print "num is a ",type(num) print "num * 2 =",num*2 print "str =", str print "str is a ",type(str) print "str * 2 =",str*2 Type in a Number: 12.34 Type in a String: Hello num = 12.34 num is a <type 'float'> num * 2 = 24.68 str = Hello str is a <type 'string'> str * 2 = HelloHello
8
"Hello, "+"World!" == "Hello, World!"
Operacije nad nizi Operacija Znak Primer Repetition ponavljanje * "i"*5 == "iiiii" Concatenation Združevanje + "Hello, "+"World!" == "Hello, World!" Pravokotnik.py #Program izracuna povrsino in obseg pravokotnika" dolzina = input(“dolzina pravokotnika:") visina = input(“Visina pravokotnika:") print “Povrsina",visina*dolzina print “Obseg",2*dolzina+2*sirina Poglej film za rezultat
9
Pretvorbe stopinj temperature.py #Converts Fahrenheit to Celsius
temp = input("Farenheit temperature:") print (temp-32.0)*5.0/9.0 Oglej si film
10
Primerjalni operatorji
znak funkcija < less than manj kot <= less than or equal to Manj ali enako kot > greater than Več kot >= greater than or equal to Več ali enako kot == Equal enako != not equal različno <> another way to say not equal Različno kot zgornje
11
Izvajajo se spodnje zamaknjene vrstice
If stavek Dvopičje Izvajajo se spodnje zamaknjene vrstice #absolutna vrednost n = input(“Stevilo? ") if n < 0: print “ABSOLUTNA VREDNOST OD",n,“JE",-n else: print " ABSOLUTNA VREDNOST OD ",n,“JE",n Zamik kot krmilni element Oglej si film
12
Modul MATH fabs(x) Return the absolute value of x. floor(x)
Return the floor of x as a float, the largest integer value less than or equal to x. exp(x) Return e**x. log(x[, base]) Return the logarithm of x to the given base. If the base is not specified, return the natural logarithm of x (that is, the logarithm to base e). Changed in version 2.3: base argument added. log10(x) Return the base-10 logarithm of x. pow(x, y) Return x**y. sqrt(x) Return the square root of x. Trigonometric functions: acos(x) Return the arc cosine of x, in radians. asin(x) Return the arc sine of x, in radians.
13
atan(x) Return the arc tangent of x, in radians. cos(x) Return the cosine of x radians. hypot(x, y) Return the Euclidean norm, sqrt(x*x + y*y). This is the length of the vector from the origin to point (x, y). sin(x) Return the sine of x radians. tan(x) Return the tangent of x radians. Angular conversion: degrees(x) Converts angle x from radians to degrees. radians(x) Converts angle x from degrees to radians. Hyperbolic functions: : pi The mathematical constant pi. e The mathematical constant e.
14
Primeri uporabe import math pi=math.pi r=input(" polmer kroga")
print"obseg kroga je",2*pi*r import math pi=math.pi r=input(" polmer kroga") print"obseg kroga je",2*pi*r print"ploscina kroga je",pi*r**2 Klik za film
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.