Thread Bitte um Hilfe für eine Studentin bei PERL Aufgaben!! (71 answers)
Opened by Anna_mary at 2010-06-20 14:34

kristian
 2010-06-22 07:55
#138707 #138707
User since
2005-04-14
684 Artikel
BenutzerIn
[Homepage] [default_avatar]
Code: (dl )
1
2
3
4
5
6
h =  { 1 : { "name"  : "Apfel",
"price" : 2.95 },
2 : { "name" : "Birne",
"price" : 1.95 },
......
}

So hatte ich die Aufgabe verstanden und das sollte doch so auch in Phyton gehen oder?

EDIT:
Scheint so:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
#-*- coding: iso-8859-1 -*-

h = { 1 : { "name" : "Bananen",
"price" : 2.95 },
2 : { "name" : "Birnen",
"price" : 1.95 },
3 : { "name" : "Pflaume",
"price" : 0.99 },
4 : { "name" : "Zitrone",
"price" : 0.45 }
}

hk = h.keys()
hk.sort()

for i in hk:
print "ID: " + str(i) + "\t" + h[i]['name'] + "\t" + str(h[i]['price'])

best = []

while True:
inp = raw_input("ID der Bestellung: ")
if inp == "Ende":
break
inp = int(inp)
if h.has_key(inp):
best.append(inp)
else:
print "Fehler: Produkt nicht vorhanden."

print
print "Rechnung:";
print "Bestellt wurde:";

sum = 0

for i in best:
print 'Produkt "' + h[i]['name'] + '"\t(ID: ' + str(i) + ')\t\tzum Preis von ' + str(h[i]['price']) + ' Euro.'
sum += h[i]['price']

print 'Der Gesamtpreis beträgt ' + str(sum) + ' Euro.'

Last edited: 2010-06-22 21:40:19 +0200 (CEST)

View full thread Bitte um Hilfe für eine Studentin bei PERL Aufgaben!!