Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. # def msg(message):
  2. # print(message)
  3. var_list = ['a', 'b', 'c', 'd', 'e']
  4.  
  5.  
  6. def func(inp):
  7. output = ""
  8. for item in inp:
  9. output += item
  10. return output
  11.  
  12. a = "I'll "
  13. b = "have "
  14. c = "a "
  15. d = "cheese "
  16. e = "sandwich."
  17.  
  18. # replacing values in a list
  19. print(func(map(eval, var_list)))
  20.  
  21. print("----------------------------------------------")
  22.  
  23. i = 0
  24. numbers = []
  25.  
  26. print("The list now: ", numbers)
  27.  
  28. while i < 6:
  29. print(f"Adding {i} to list")
  30. i = i + 1
  31. numbers.append(i)
  32.  
  33. print("The list now: ", numbers)
  34. # end=' ' space after each output //there is no spacing after each letter in end=' '//
  35. print("\nThe numbers in the list: ")
  36. for num in numbers:
  37. print(num, end=', ')
  38.  
  39.  
  40. print("\n----------------------------------------------")
  41. # Convert a list to a string join() function,
  42. # but if the list contains integers then convert it into string and then use join()
  43.  
  44. a = ["Geeks", "for", "Geeks"]
  45. # print the list using join function()
  46. print(' '.join(a))
  47.  
  48. print("\n----------------------------------------------")
  49.  
  50. # print the list by converting a list of
  51. # integers to string
  52. a = [1, 2, 3, 4, 5]
  53. print(str(a)[1:-1])
  54.  
  55. # if list is not a string
  56. # Use map() to convert each item in the list to a string and join
  57.  
  58. a = [1, 2, 3, 4, 5]
  59. print(' '.join(map(str, a)))
  60.  
  61. # print "in new line"
  62. print('\n'.join(map(str, a)))
  63.  
  64.  
  65. print("\n-------------------------------------------------")
  66.  
  67. a = 35
  68. a = str(a)
  69. total = (sum(int(x) for x in a))
  70. print(f"Sum = {total}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement