1 / 26

If stavek

If stavek. #o ceni... price = int(raw_input("What price? ")) if price == 100: # če je cena enaka 100 print “vzamem!" # vzamem else: if price > 500: # če je cena več kot 500 print “ni šans!" else: if price > 200: print “Ali se bi pogajala?"

talor
Download Presentation

If stavek

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. If stavek #o ceni... price = int(raw_input("What price? ")) if price == 100: # če je cena enaka 100 print “vzamem!" # vzamem else: if price > 500: # če je cena več kot 500 print “ni šans!" else: if price > 200: print “Ali se bi pogajala?" else: print “to pa ni cena!"

  2. If in SYS Primer ko je izhod iz zanke predčasen, oziroma pogoj ni izpolnjen za izvršitev jedra zanke import sys # kako uidemo iz zanke print “Tukaj začnemo" j = 5 #j dobi vrednost 5 if j > 10: # če je j večji od 10 print "This is never printed“ #nikoli stiskano else: sys.exit() #izhod iz zanke!!!!

  3. Meniji in if menu = """ Izberi lik (1-3): 1) Kvadrat 2) Pravokotnik 3) Trikotnik pravokotni """ shape = int(raw_input(menu)) if shape == 1: length = float(raw_input(“Dolžina: ")) #vpraša za stranico print “Ploščina kvadrata = ", length ** 2 elif shape == 2: length = float(raw_input(" Dolžina: ")) width = float(raw_input(“Širina: ")) print “Ploščina pravokotnika = ", length * width elif shape == 3: length = float(raw_input(“stranica a: ")) width = float(raw_input(“stranica b: ")) print “ploščina = ", length * width/2 else: print “poskusi ponovno, napaka"

  4. Še malo dodelan meni angleški

  5. For stavek

  6. Še for

  7. While

  8. Še os SYS

  9. Moduli 1

  10. Moduli 2

  11. Funkcije in Time

  12. Delo z datotekami

  13. Popravljeno delo z datoteko # izboljšana varianta # Odpremo datoteko za branje(r) inp = open("menu.txt","r") # iteriramo(ponavljamo) po datoteki in izpisujemo vsako vrsto for line in inp: print line.rstrip()#poreže posebne znake in jih ne tiska # ne pozabimo zapreti datoteke inp.close()

  14. Kopiranje datotek # Naredimo kopijo datoteke MENU.TXT v MENU.BAK # odpremo datoteki tako za branje kot pisanje) inp = open("menu.txt","r") outp = open("menu.bak","w") # beremo datoteko in pišemo v drugo for line in inp: outp.write(line) print "1 file copied..." # Ne pozabimo zapreti datotek inp.close() outp.close()

  15. Meni_datoteke_2_date import time # Create daily menu based on MENU.TXT inp = open("menu.txt","r") # First open the files to read(r) and write(w) outp = open("menu.prn","w") today = time.localtime(time.time()) # Create todays date string print today#izpis oblike datuma v pythonu theDate = time.strftime("%A %B %d", today) print theDate#izpis v “pravi obliki” datuma outp.write("Menu for %s\n\n" % theDate) # Add Banner text and a blank line for line in inp: # copy each line of menu.txt to new file outp.write(line) print "Menu created for %s..." % theDate inp.close() # Now close the files outp.close() Note that we use the time module to get todays date (time.time()) and convert it into a tuple of values (time.localtime()) which are then used by time.strftime() to produce a string which, when inserted into a title message using string formatting, looks like:

  16. Join in split besedilo

  17. Štetje besed v datoteki

  18. Velike-male

  19. Widgets –dodatno okno

  20. Še widgets

  21. Osnova risanja

  22. Krog from Tkinter import * p=Canvas(height=600,width=600,bg="grey") #delovna površina xy=30,30,550,550 p.create_arc(xy, start=0, extent=90, fill="red") p.create_arc(xy, start=90, extent=90, fill="yellow") p.create_arc(xy, start=180, extent=90, fill="green") p.create_arc(xy, start=270, extent=90, fill="blue") p.create_text(560,560,fill="blue",font="Tahoma",text="vaja") p.pack() mainloop()

  23. Seštevalnik

  24. Smerokaz

  25. Koordinatni sistem in lega točke from Tkinter import * x=input("Vpiši koordinato x: ") y=input("Vpiši koordinato y: ") povrsina=Canvas(width=300, height=315) povrsina.pack() povrsina.create_line(150,0,150,300) povrsina.create_line(0,150,300,150) povrsina.create_text(30,10,text='2. kvadrant') povrsina.create_text(270,10,text='1. kvadrant') povrsina.create_text(30,300,text='3. kvadrant') povrsina.create_text(270,300,text='4. kvadrant') povrsina.create_line(2,149,2,152,fill='blue') povrsina.create_line(150,149,150,152, fill='blue') povrsina.create_line(300,149,300,152, fill='blue') povrsina.create_text(11,156,text='-150',fill='blue') povrsina.create_text(160,156,text='0',fill='blue') povrsina.create_text(290,156,text='150',fill='blue') povrsina.create_oval(x+150-2,150-y-2,x+150+2,150-y+2,fill='red') #tekst1='Tocka '+str(x)+','+str(y)+' je v 1. kvadrantu' if x>0: if y>0: povrsina.create_text(150,310,text='Tocka T('+str(x)+','+str(y)+') je v 1. kvadrantu',fill='red') else: povrsina.create_text(150,310,text='Tocka T('+str(x)+','+str(y)+') je v 4. kvadrantu',fill='red') elif x<0: if y>0: povrsina.create_text(150,310,text='Tocka T('+str(x)+','+str(y)+') je v 2. kvadrantu',fill='red') else: povrsina.create_text(150,310,text='Tocka T('+str(x)+','+str(y)+') je v 3. kvadrantu',fill='red') else: povrsina.create_text(150,310,text='Tocka je na koordinatni crti',fill='red') mainloop()

More Related