vendredi 18 décembre 2020

Python: Define own function called "randomcall"

so i am stuck on a certain problem I have to solve and was wondering if you guys could help me in my situation (i am really new to python and programming by itself). So the task i got is, to define a own new function to pick out of a Dictionary called "phonebook" random people and print out to pretend calling them. Something like "randomcall(phonebook,10) and then it prints: Calling Peter at 1800650, and 9 others.

    import random
    
    for name in range(phonebook):
        name = random.choice(list(phonebook))
        phonebook = phonebook[name]
        print(f'Lets call {name} with {phonebook}')

phonebook = {"martin":12345,"anna":65478,"klaus":5468764,"hans":748463,"peter":84698416,"ulrich":3416846546,"frank":4789749,"lukas":798469,"ferdinand":68465131}

randomcall(phonebook,3)

randomcall("", 5)```



Aucun commentaire:

Enregistrer un commentaire