Testpage: Unterschied zwischen den Versionen

Aus Unterrichtsmaterial
Wechseln zu:Navigation, Suche
Zeile 6: Zeile 6:
 
</tagcloud>
 
</tagcloud>
  
<br />
+
<br /><syntaxhighlight lang="python3" line="1">
 +
# Import the modules
 +
import sys
 +
import random
 +
 
 +
ans = True
 +
 
 +
while ans:
 +
    question = raw_input("Ask the magic 8 ball a question: (press enter to quit) ")
 +
   
 +
    answers = random.randint(1,8)
 +
   
 +
    if question == "":
 +
        sys.exit()
 +
   
 +
    elif answers == 1:
 +
        print "It is certain"
 +
   
 +
    elif answers == 2:
 +
        print "Outlook good"
 +
   
 +
    elif answers == 3:
 +
        print "You may rely on it"
 +
   
 +
    elif answers == 4:
 +
        print "Ask again later"
 +
   
 +
    elif answers == 5:
 +
        print "Concentrate and ask again"
 +
   
 +
    elif answers == 6:
 +
        print "Reply hazy, try again"
 +
   
 +
    elif answers == 7:
 +
        print "My reply is no"
 +
   
 +
    elif answers == 8:
 +
        print "My sources say no"
 +
</syntaxhighlight>

Version vom 5. März 2020, 10:41 Uhr

Übersicht
Roadmap.JPG
Themenfeld Big Data
Editiert am 05.3.2020



 1 # Import the modules
 2 import sys
 3 import random
 4 
 5 ans = True
 6 
 7 while ans:
 8     question = raw_input("Ask the magic 8 ball a question: (press enter to quit) ")
 9     
10     answers = random.randint(1,8)
11     
12     if question == "":
13         sys.exit()
14     
15     elif answers == 1:
16         print "It is certain"
17     
18     elif answers == 2:
19         print "Outlook good"
20     
21     elif answers == 3:
22         print "You may rely on it"
23     
24     elif answers == 4:
25         print "Ask again later"
26     
27     elif answers == 5:
28         print "Concentrate and ask again"
29     
30     elif answers == 6:
31         print "Reply hazy, try again"
32     
33     elif answers == 7:
34         print "My reply is no"
35     
36     elif answers == 8:
37         print "My sources say no"