Hallo und Frage zu Schleifen Übungen

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
ete
User
Beiträge: 218
Registriert: Montag 19. Februar 2007, 13:19
Kontaktdaten:

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
Benutzeravatar
nkoehring
User
Beiträge: 543
Registriert: Mittwoch 7. Februar 2007, 17:37
Wohnort: naehe Halle/Saale
Kontaktdaten:

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")
[url=http://www.python-forum.de/post-86552.html]~ Wahnsinn ist auch nur eine andere Form der Intelligenz ~[/url]
hackerkey://v4sw6CYUShw5pr7Uck3ma3/4u7LNw2/3TXGm5l6+GSOarch/i2e6+t2b9GOen7g5RAPa2XsMr2
mitsuhiko
User
Beiträge: 1790
Registriert: Donnerstag 28. Oktober 2004, 16:33
Wohnort: Graz, Steiermark - Österreich
Kontaktdaten:

nkoehring hat geschrieben:Ansonsten gibt es noch die integrierte Hilfe:

Code: Alles auswählen

help("for")
Für Syntaxelemente funktioniert das nicht.
TUFKAB – the user formerly known as blackbird
Benutzeravatar
birkenfeld
Python-Forum Veteran
Beiträge: 1603
Registriert: Montag 20. März 2006, 15:29
Wohnort: Die aufstrebende Universitätsstadt bei München

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.
Dann lieber noch Vim 7 als Windows 7.

http://pythonic.pocoo.org/
Benutzeravatar
Rebecca
User
Beiträge: 1662
Registriert: Freitag 3. Februar 2006, 12:28
Wohnort: DN, Heimat: HB
Kontaktdaten:

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 ...
...
Benutzeravatar
nkoehring
User
Beiträge: 543
Registriert: Mittwoch 7. Februar 2007, 17:37
Wohnort: naehe Halle/Saale
Kontaktdaten:

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.
[url=http://www.python-forum.de/post-86552.html]~ Wahnsinn ist auch nur eine andere Form der Intelligenz ~[/url]
hackerkey://v4sw6CYUShw5pr7Uck3ma3/4u7LNw2/3TXGm5l6+GSOarch/i2e6+t2b9GOen7g5RAPa2XsMr2
Benutzeravatar
mq
User
Beiträge: 124
Registriert: Samstag 1. Januar 2005, 19:14

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.
ete
User
Beiträge: 218
Registriert: Montag 19. Februar 2007, 13:19
Kontaktdaten:

Vielen Dank für die Tips!

@Rebecca

Ich werds gleich mal probieren :D
cime
User
Beiträge: 152
Registriert: Dienstag 24. Mai 2005, 15:49

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
Bernhard
User
Beiträge: 136
Registriert: Sonntag 15. Januar 2006, 20:31
Wohnort: Greifswald
Kontaktdaten:

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.
Antworten