Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- A function which when called displays a nursery rhyme.
- """
- def nursery_song():
- nursery_rhyme=[]
- howmanylines=int(input("How many lines do nursery rhyme has? "))
- for item in range(howmanylines):
- lines=input("Here is the line indexed to number "+str(item)+": ")
- item+=1
- nursery_rhyme.append(lines)
- for line in nursery_rhyme:
- print(line)
- nursery_song()
- """
- A function with one parameter, name,
- which will be the name of a person.
- The function should then “sing” Happy Birthday to that person,
- inserting their name at the correct point.
- """
- name=input("Enter name: ")
- def happy_birthday(name):
- age=int(input("Enter your age: "))
- happybirthdaySong=[]
- line1="Happy birthday to you. \nHappy birthday dear {},".format(name)
- line2="\nHappy birthday to you."
- line3="\nHow old are you now? I am {} years old,".format(age)
- line4= "\nHappy birthday dear {},".format(name)
- line5="\nHappy birthday to you."
- song=str(line1)+str(line2)+str(line3)+str(line4)+str(line5)
- happybirthdaySong.append(song)
- for element in happybirthdaySong:
- return element
- birthday_party=happy_birthday(name)
- print(birthday_party)
- """
- A function which generates a random password of any length?
- the function should accept one parameter,
- the desired password length, and return a password
- """
- import string
- from random import *
- characters=input("Enter characters for your password: ")
- def mypass(characters):
- characters = string.ascii_letters + string.punctuation + string.digits
- password = "".join(choice(characters) for char in range(randint(4, 9)))
- return password
- my_password=mypass(characters)
- print(my_password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement