Friday, January 14, 2011

Whose Breasts Are Bigger

Integers include (loops, sequences, functions POS1: 1BHIF)

anzzahlen.py Write a program that reads a line and this line, count how many whole numbers occur. Any character that is not a digit, is regarded as not belonging to a number.
example
input :
 that's a number 123 and have a 1 and two 3213x23123 
edition :
 found 4 numbers. 
The program should output correct sentences, that "No numbers." When in the command are not numbers or "A Number found." When a number was in the input. From 4 then, the number will be issued, for example, "found six figures."

Possible solution:
 "" "
author: Haberstroh, Harald
matnr: d09666
file: anzzahlen.py
desc: Count integer
example
this is a number 123 and another one and two 3213x23123
Issue: 4 numbers found

date: 14/01/2011
class: teachers
Catnr: 33
"" "
#---+---- a ----+- --- 2 ----+---- 3 ----+---- 4 ----+---- 5 ----+---- 6 ----+- --- 7 ----+----

def anz_zahlen (string):
"" "determines the number of integers in the string" ""
count = 0
in_zahl = False
for character in string:
sign in if "0123456789"
in_zahl if not: count + = 1

in_zahl = True else
:
in_zahl = return False def
number

output (number):
"" "is German sentence with number" ""
if number == 0:
print ("No number.") elif number == 1
:
print ("found a number. ") elif number == 2
:
print (" found two numbers ") elif number == 3
: print
(". found three numbers ")
else
print (number,".. found numbers ")

def main ():
"" "EVA Eingave processing issue - the main program" ""
string = input (">") anz_zahlen
number = (string)
issue (no.) def

test ():
"" "Testing anz_zahlen () and output ()"""
string =" anz_zahlen the number is a number 123 and another one and another 3213x23123 "
= (string)
issue (no.) (anz_zahlen ("no")) output

output (anz_zahlen ("a number 123"))
output (anz_zahlen (two 23 and 324 "))
output (anz_zahlen (" three 23 34 22 "))
output (anz_zahlen (four 234 234 234 45 ")) output
(anz_zahlen (" 5234234234 45 "))


if __name__ == '__main__':
main ()
# test ()
Note that I own here function test () 've done to be able to taste many test cases again and again slightly. Instead main () only needs to test () be called.
The program would also be without the function test () complete and correct. test () only helped in the development in troubleshooting.

0 comments:

Post a Comment