Seite 1 von 1

Hallo und Frage zu Schleifen Übungen

Verfasst: Montag 19. Februar 2007, 13:24
von ete
Hallo!

Ich bin neu hier und habe eine Frage. Ich habe angefangen Python zu lernen (keine Programmier Vorkenntnisse) und komme ganz gut vorran.

Ich wollte fragen, ob jemand Links für einfache Aufgaben kennt. Ich möchte meine Praxis ein wenig vertiefen. Ich bin gerdade bei der for Schleife und merke, das mir ein wenig die Anwendung fehlt.

Falls jemand einfache Aufgaben kennt, wäre ich sehr dankbar!

ciao ete

Verfasst: Montag 19. Februar 2007, 13:39
von nkoehring
Hallo und willkommen im Forum...

Da ich nicht weiß, was du bisher zu Rate ziehst, liste ich einfach mal alles auf, was mir spontan einfaellt:
Ansonsten gibt es noch die integrierte Hilfe:

Code: Alles auswählen

help("for")

Verfasst: Montag 19. Februar 2007, 14:06
von mitsuhiko
nkoehring hat geschrieben:Ansonsten gibt es noch die integrierte Hilfe:

Code: Alles auswählen

help("for")
Für Syntaxelemente funktioniert das nicht.

Verfasst: Montag 19. Februar 2007, 14:14
von birkenfeld
Doch, wenn alles richtig eingerichtet ist, schon.

Code: Alles auswählen

Sorry, topic and keyword documentation is not available because the Python
HTML documentation files could not be found.  If you have installed them,
please set the environment variable PYTHONDOCS to indicate their location.

Verfasst: Montag 19. Februar 2007, 14:17
von Rebecca
Wie waere es mit folgenden Aufgaben:

1.) Schreibe ein Programm, das die die Fakultaet einer Zahl berechnet (n! = 1*2*3*...*n)

2.) Schreibe ein Programm, welches das kleine Einmaleins ausgibt, etwa so:

Code: Alles auswählen

1 2 3 4 ...
2 4 6 8 ...
3 6 9 12 ...
4 8 12 16 ...
...

Verfasst: Montag 19. Februar 2007, 14:20
von nkoehring
blackbird hat geschrieben:
nkoehring hat geschrieben:Ansonsten gibt es noch die integrierte Hilfe:

Code: Alles auswählen

help("for")
Für Syntaxelemente funktioniert das nicht.

Code: Alles auswählen

  ------------------------------------------------------------------------
  
  7.3 The for statement
  
  The for statement is used to iterate over the elements of a sequence
  (such as a string, tuple or list) or other iterable object:

        for_stmt         ::=     "for" target_list[1] "in" expression_list[2] ":" suite[3]
                        ["else" ":" suite[4]]
  
  Download entire grammar as text.[5]
  
  The expression list is evaluated once; it should yield an iterable
  object. An iterator is created for the result of the expression_list.
  The suite is then executed once for each item provided by the iterator,
  in the order of ascending indices. Each item in turn is assigned to the
  target list using the standard rules for assignments, and then the suite
  is executed. When the items are exhausted (which is immediately when the
  sequence is empty), the suite in the else clause, if present, is
  executed, and the loop terminates.
  
  A break statement executed in the first suite terminates the loop
  without executing the else clause's suite. A continue statement executed
  in the first suite skips the rest of the suite and continues with the
  next item, or with the else clause if there was no next item.
  
  The suite may assign to the variable(s) in the target list; this does
  not affect the next item assigned to it.
  
  The target list is not deleted when the loop is finished, but if the
  sequence is empty, it will not have been assigned to at all by the loop.
  Hint: the built-in function range() returns a sequence of integers
  suitable to emulate the effect of Pascal's for i := a to b do; e.g.,
  range(3) returns the list [0, 1, 2].
  
  Warning: There is a subtlety when the sequence is being modified by the
  loop (this can only occur for mutable sequences, i.e. lists). An
  internal counter is used to keep track of which item is used next, and
  this is incremented on each iteration. When this counter has reached the
  length of the sequence the loop terminates. This means that if the suite
  deletes the current (or a previous) item from the sequence, the next
  item will be skipped (since it gets the index of the current item which
  has already been treated). Likewise, if the suite inserts an item in the
  sequence before the current item, the current item will be treated again
  the next time through the loop. This can lead to nasty bugs that can be
  avoided by making a temporary copy using a slice of the whole sequence,
  e.g.,
  
  
  for x in a[:]:
      if x < 0: a.remove(x)
  
  
  ------------------------------------------------------------------------
  Release 2.4.3, documentation updated on 29 March 2006.

Verfasst: Montag 19. Februar 2007, 14:34
von mq
Edit:
Argh, birkenfelds Post ueberlesen. Wie loesch ich hier meine Posts?

Code: Alles auswählen

>>> help('for')

Sorry, topic and keyword documentation is not available because the Python
HTML documentation files could not be found.  If you have installed them,
please set the environment variable PYTHONDOCS to indicate their location.
Sieht so aus, als waere das optional.

Verfasst: Montag 19. Februar 2007, 16:35
von ete
Vielen Dank für die Tips!

@Rebecca

Ich werds gleich mal probieren :D

Verfasst: Montag 19. Februar 2007, 17:34
von cime
du kannst ja mal beim Bundeswettbewerb informatik (http://bwinf.de/) schauen, die aufgabe der ersten Runde sind oft relativ einfach zu loesen, vorallem die junioaufgabe sollte im bereich des moeglichen liegen ... schau die am besten einfach auch die aufgaben der letzten jahre an

Verfasst: Montag 19. Februar 2007, 22:55
von Bernhard
Meinst Du das jetzt ernst? Die Aufgaben des Bundeswettbewerbs für jemanden, der gerade versucht, die for-Schleife zu verinnerlichen?

Scheint mir ein wenig anspruchsvoll.
Bernhard



@ete: Schreibe ein Programm, das folgendes ausgibt:

*****.....
.*****....
..*****...
...*****..
....*****.
.....*****
und zwar für beliebig viele Sternchen über eine beliebig einzugebende Zeilenzahl.