Advertisement
lubattillah

challenge4_102

May 30th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. """
  2. A function which when called displays a nursery rhyme.
  3. """
  4.  
  5. def nursery_song():
  6. nursery_rhyme=[]
  7. howmanylines=int(input("How many lines do nursery rhyme has? "))
  8. for item in range(howmanylines):
  9. lines=input("Here is the line indexed to number "+str(item)+": ")
  10. item+=1
  11. nursery_rhyme.append(lines)
  12. for line in nursery_rhyme:
  13. print(line)
  14. nursery_song()
  15.  
  16. """
  17. A function with one parameter, name,
  18. which will be the name of a person.
  19. The function should then “sing” Happy Birthday to that person,
  20. inserting their name at the correct point.
  21. """
  22.  
  23. name=input("Enter name: ")
  24. def happy_birthday(name):
  25. age=int(input("Enter your age: "))
  26. happybirthdaySong=[]
  27. line1="Happy birthday to you. \nHappy birthday dear {},".format(name)
  28. line2="\nHappy birthday to you."
  29. line3="\nHow old are you now? I am {} years old,".format(age)
  30. line4= "\nHappy birthday dear {},".format(name)
  31. line5="\nHappy birthday to you."
  32. song=str(line1)+str(line2)+str(line3)+str(line4)+str(line5)
  33. happybirthdaySong.append(song)
  34. for element in happybirthdaySong:
  35. return element
  36. birthday_party=happy_birthday(name)
  37. print(birthday_party)
  38.  
  39.  
  40. """
  41. A function which generates a random password of any length?
  42. the function should accept one parameter,
  43. the desired password length, and return a password
  44. """
  45.  
  46. import string
  47. from random import *
  48. characters=input("Enter characters for your password: ")
  49. def mypass(characters):
  50. characters = string.ascii_letters + string.punctuation + string.digits
  51. password = "".join(choice(characters) for char in range(randint(4, 9)))
  52. return password
  53. my_password=mypass(characters)
  54. print(my_password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement