Tuesday, May 13, 2014

Small python program

The first program after “Hello World”:

#!/usr/bin/python
wort = raw_input(”Wort:”)
wiederholen = input(”Anzahl:”)
if wiederholen == 0:
   print”0 mal geht ja wohl nicht, bitte nochmal eingeben”
  wiederholen = input(”noch ein Versuch:”)
for i in range(0, wiederholen):
  print wort


The program ask for a text-string and a number. Both is stored
as variable.
A minimal fault tolerance is the if statemenf for 0 so that a message appears.
Then the word is written as often as the variable says to the terminal.


Learned: using variable, if statement, for loop and printing variable.


No comments:

Post a Comment