dimanche 18 février 2018

Python: How do you run a function without parameters?

Write a function 'music_func' that takes 3 parameters -- music type, music group, vocalist -- and prints them all out as shown in the example below. In case no input is provided by the user, the function should assume these values for the parameters: "Classic Rock", "The Beatles", "Freddie Mercury".

For example:

Input:

Alternative Rock,Pearl Jam,Chris Cornell

Output:

The best kind of music is Alternative Rock The best music group is Pearl Jam The best lead vocalist is Chris Cornell

Note: The print statements will go inside the music_func(). For example: print("The best kind of music is" + ...)

    #definition for music_func goes here
def music_func(a,b,c):
if a is None or b is None or c is None:
    print("The best kind of music is Classic Rock")
    print("The best music group is The Beatles")
    print("The best lead vocalist is Freddie Mercury")
else:
    print("The best kind of music is",a)
    print("The best music group is",b)
    print("The best lead vocalist is",c)
    return
def main():
    music, group, singer = input().split(',')
    music_func(music, group, singer)
    music_func() #This is suppose to print the first if-statement
main()

Aucun commentaire:

Enregistrer un commentaire