Guest User

Untitled

a guest
Jul 16th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. import numpy as np
  2.  
  3. # 1)
  4. """
  5. Define a function MaxOfThree() that takes three numbers as arguments
  6. and returns the largest of them (Use If, elif and else).
  7. For example, MaxOfThree(1, 2, 3) should return 3
  8. """
  9. def MaxOfThree(x1, x2, x3):
  10. if (type(x1) == int and type(x2) == int and type(x3) == int):
  11. if(x1 > x2 and x1> x3):
  12. return x1
  13. elif(x2 > x1 and x2> x3):
  14. return x2
  15. else:
  16. return x3
  17. else:
  18. print("Dambass, input numbers only!")
  19.  
  20. print(MaxOfThree(1,"2",3))
  21.  
  22.  
  23. # 2)
  24. """
  25. Define a function MySum() and a function MyMultiply() that sums
  26. and multiplies (respectively) all the numbers in a list of
  27. numbers (Use for). For example, s MySum([1, 2, 3, 4]) should return 10,
  28. and MyMultiply([1, 2, 3, 4]) should return 24.
  29. """
  30. n = range(1, 6)
  31. def MySum(list1):
  32. sum =0
  33. for l in list1:
  34. sum += l
  35. return sum
  36.  
  37. def MyMultiply(list2):
  38. mult = 1
  39. for l in list2:
  40. mult *= l
  41. return mult
  42.  
  43. print(MySum(n))
  44. print(MyMultiply(n))
  45.  
  46.  
  47. # 3)
  48. """
  49. Define a function MyMean() that receives an unknown amount
  50. of input values from a user and returns the mean value of all the
  51. input values (Use while). For example: if the user provides [1, 2, 3, 4],
  52. the MyMean(), should return 2.5
  53. """
  54. def MyMean(l):
  55. print(np.mean(l))
  56.  
  57. final = []
  58. while True:
  59. means = input('Please enter a number: ')
  60. if not means:
  61. break
  62. final.append(int(means))
  63.  
  64. MyMean(final)
  65. """
  66. Define a function MyStars() that takes a list of integers and prints
  67. a string of stars which has the length of a value of an integer to
  68. the screen. For example, MyStars([3, 9, 7]) should print the following:
  69. ***
  70. *********
  71. *******
  72.  
  73. """
  74. numbers = []
  75.  
  76. while True:
  77. means = input('Please enter a number: ')
  78. if not means:
  79. break
  80. numbers.append(int(means))
  81.  
  82.  
  83. def MyStars(l):
  84. for i in l:
  85. print("*"*i)
  86.  
  87. MyStars(numbers)
Add Comment
Please, Sign In to add comment