Python :: Aufgabe #248 :: Lösung #5
5 Lösungen
#248
Zufällige Buchstaben für Stadt-Land-Fluss
Anfänger - Python
von charlyP
- 26.03.2020 um 00:24 Uhr
Es soll ein beliebiger Buchstabe des Alphabets (ohne Umlaute) ausgegeben werden und dann auf Anforderung des Nutzers immer wieder ein weiterer Buchstabe, wobei jeder Buchstabe des Alphabets nur ein Mal ausgegeben werden darf.
Viel Spaß
Viel Spaß
#5
von torstenkn (150 Punkte)
- 18.04.2020 um 00:07 Uhr
# Imports
from string import ascii_lowercase
from random import randint
# Initiate pool of available chars
charpool = list(ascii_lowercase)
# Perform loop as long as charpool not empty
while len(charpool) > 0:
# Get random number
nextchar = randint(0, len(charpool)) - 1
# Print Char
print("Your Letter is: " + str(charpool.pop(nextchar)))
if len(charpool) != 0:
# Need more chars?
answer = input("Do you need another char? (Y/n)")
if answer != "" and answer != "y" and answer != "Y":
break
else:
print("All letters have been used!")Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1
